当我运行这个剧本时,它找不到ansible_uptime_seconds变量。但是ansible hostname -m setup提供了这个变量。我使用的是ansible 2.9.23版本。
- hosts: all
become: yes
become_method: sudo
gather_facts: yes
tasks:
- name: Print all available facts
ansible.builtin.debug:
var: ansible_facts获取此消息
'ansible_uptime_seconds' is undefined如何在实战手册中获取此值?
发布于 2021-07-30 18:01:56
当在没有setup模块的情况下收集facts时,事实名称是uptime_seconds。但是,当使用setup模块收集时,它的"ansible_uptime_seconds"。
---
- name: Sample playbook
connection: local
# gather_facts: false
hosts: localhost
tasks:
- name: print uptime sec
debug:
msg: "{{ ansible_facts.uptime_seconds }}"上述攻略的输出为:
PLAY [Sample playbook] *********************************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************************************
ok: [localhost]
TASK [print uptime sec] **********************************************************************************************************************************************************
ok: [localhost] => {
"msg": "172603"
}
PLAY RECAP *********************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0https://stackoverflow.com/questions/68595187
复制相似问题