致使讀不到 inventory,同時使用兩種格式能夠兼容各個版本,以下node
cat .ansible.cfg [defaults] # inventory control group_vars # < 2.8 hostfile = xxx # >=2.8 inventory = xxx library = /usr/share/ansible:xxx
ansible_distribution_version
在 centos 上在 2.7.11 和 2.8.1 結果不一樣,致使相同的 playbook 在升級 ansible 後沒法正常運行python
觀察 ubuntu 和 centos 的相關變量以下,最終採用ansible_lsb.release
來代替ansible_distribution_version
,能夠加絨Ubuntu 和 centos 中ansible 的各個版本。ubuntu
# on ubuntu trusty ## ansible 1.5.4 root@iZhp33qecbruyuw1awh6rfZ:~# ansible localhost -m setup -a "filter=ansible_os_family" localhost | success >> { "ansible_facts": { "ansible_os_family": "Debian" }, "changed": false } root@iZhp33qecbruyuw1awh6rfZ:~# ansible localhost -m setup -a "filter=ansible_distribution_version" localhost | SUCCESS => { "ansible_facts": { "ansible_distribution_version": "14.04" }, "changed": false } root@iZhp33qecbruyuw1awh6rfZ:~# ansible localhost -m setup -a "filter=ansible_lsb" localhost | success >> { "ansible_facts": { "ansible_lsb": { "codename": "trusty", "description": "Ubuntu 14.04.5 LTS", "id": "Ubuntu", "major_release": "14", "release": "14.04" } }, "changed": false } ## ansible 2.8.1 root@iZhp33qecbruyuw1awh6rfZ:~# ansible localhost -m setup -a "filter=ansible_os_family" localhost | SUCCESS => { "ansible_facts": { "ansible_os_family": "Debian" }, "changed": false } root@iZhp33qecbruyuw1awh6rfZ:~# ansible localhost -m setup -a "filter=ansible_distribution_version" localhost | SUCCESS => { "ansible_facts": { "ansible_distribution_version": "14.04" }, "changed": false } root@iZhp33qecbruyuw1awh6rfZ:~# ansible localhost -m setup -a "filter=ansible_lsb" localhost | success >> { "ansible_facts": { "ansible_lsb": { "codename": "trusty", "description": "Ubuntu 14.04.5 LTS", "id": "Ubuntu", "major_release": "14", "release": "14.04" } }, "changed": false } # on centos 7.5 ## ansible 2.7.11 [root@node11 ~]# ansible localhost -m setup -a "filter=ansible_os_family" localhost | SUCCESS => { "ansible_facts": { "ansible_os_family": "RedHat" }, "changed": false } [root@node11 ~]# ansible localhost -m setup -a "filter=ansible_distribution_version" localhost | SUCCESS => { "ansible_facts": { "ansible_distribution_version": "7.5.1804" }, "changed": false } [root@node11 ~]# ansible localhost -m setup -a "filter=ansible_lsb" localhost | SUCCESS => { "ansible_facts": { "ansible_lsb": { "codename": "Core", "description": "CentOS Linux release 7.5.1804 (Core)", "id": "CentOS", "major_release": "7", "release": "7.5.1804" } }, "changed": false } ## ansible 2.8.1 [root@node11 ~]# ansible localhost -m setup -a "filter=ansible_os_family" localhost | SUCCESS => { "ansible_facts": { "ansible_os_family": "RedHat", "discovered_interpreter_python": "/usr/bin/python" }, "changed": false } [root@node11 ~]# ansible localhost -m setup -a "filter=ansible_distribution_version" localhost | SUCCESS => { "ansible_facts": { "ansible_distribution_version": "7" }, "changed": false } [root@node11 ~]# ansible localhost -m setup -a "filter=ansible_lsb" localhost | SUCCESS => { "ansible_facts": { "ansible_lsb": { "codename": "Core", "description": "CentOS Linux release 7.5.1804 (Core)", "id": "CentOS", "major_release": "7", "release": "7.5.1804" } }, "changed": false }