6

'ansible_facts' 中 Ubuntu 18.04 报告分发信息的示例:

$ ansible -i hosts ubuntu1804 -u root -m setup -a "filter=ansible_distribution*"
ubuntu1804 | SUCCESS => {
    "ansible_facts": {
        "ansible_distribution": "Ubuntu", 
        "ansible_distribution_file_parsed": true, 
        "ansible_distribution_file_path": "/etc/os-release", 
        "ansible_distribution_file_variety": "Debian", 
        "ansible_distribution_major_version": "18", 
        "ansible_distribution_release": "bionic", 
        "ansible_distribution_version": "18.04"
    }, 
    "changed": false
}

针对 Ubuntu 20.04 的相同命令示例:

$ ansible -i hosts ubuntu2004 -u root -m setup -a "filter=ansible_distribution*"
ubuntu2004 | SUCCESS => {
    "ansible_facts": {}, 
    "changed": false
}

这是 Ubuntu 或 Ansible 的问题吗?有解决方法吗?

4

2 回答 2

7

问题已通过今天的更新解决ansible 2.9.7

于 2020-04-29T20:10:19.560 回答
0

经过大量研究以找出 Ubuntu 20.04 版本,然后我们发布了一个使用 ansible version-2.5.1 的版本

- hosts: localhost
  become: true
  gather_facts: yes
  tasks:
  - name: System details
    debug:
      msg: "{{ ansible_facts['lsb']['release'] }}"

  - name: ubuntu 18
    shell: echo "hello 18"
    register: ub18
    when: ansible_facts['lsb']['release'] == "18.04"

  - debug:
     msg: "{{ ub18 }}"

  - name: ubuntu 20
    shell: echo "hello 20"
    register: ub20
    when: ansible_facts['lsb']['release'] == "20.04"

  - debug:
     msg: "{{ ub20 }}"
于 2022-01-18T10:46:47.000 回答