PLAY [test packageing modules] **************************************************
TASK [upgrade all packages] ***************************************************** changed: [cube4200]
TASK [install a package] ******************************************************** changed: [cube4200]
PLAY RECAP ********************************************************************** cube4200 : ok=2 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 [anna@cube4200 ~]$ which git /usr/bin/git [anna@cube4200 ~]$ git --version git version 1.8.3.1
Notice: the update task took long time to update all packages.
packaging module: apt
apt is Ubuntu package management tool.
In this example, I am going to install git in two different linux, one use yum on CentOS, anther one use apt on Debian. So I need to add some condition to let ansible know which node should use yum or apt. Before running site.yml I can use ansible web1 -m gather_facts |grep distribution to see the OS of nodes.
1 2 3 4 5 6 7 8 9 10 11
tasks: - name: test yum module yum: name: git state: latest when: ansible_facts['distribution'] == "CentOS" # this is from gather_facts - name: test apt module apt: name: git state: latest when: ansible_facts['distribution'] == "Debian"
During running, I can see ansible will judge which command (apt or yum) to use.
Notice: sometime package will have different name in different OS, under this situation, package module will not work, I still need to use yum or apt with gather_facts conditon to install packages.