Ansible: How installing a group of packages?
Installing a set of packages with Ansible
The context
I need to install a group of packages on multiple Linux servers. Ansible is the right tool for that.The host file: hosts
[test_machines]test1.my_domain.com
test2.my_domain.com
[dev]
dev1.my_domain.com
dev2.my_domain.com
[uat]
uat1.my_domain.com
uat2.my_domain.com
[prod]
prd1.my_domain.com
prd2.my_domain.com
The playbook : add_packages.yml
- hosts: allvars_files:
- data/all_my_packages.yml
tasks:
- name: Ensure a set of packages is installed.
yum:
name={{ item.name }}
state={{ item.state }}
with_items: '{{ packages }}'
The datafile: data/all_my_packages.yml
packages:- { name: 'glibc.i686', state: 'present' }
- { name: 'glibc.x86_64', state: 'present' }
- { name: 'glibc-common', state: 'present' }
- { name: 'glibc-devel', state: 'present' }
- { name: 'glibc-headers', state: 'present' }
- { name: 'libstdc++.i686', state: 'present' }
- { name: 'libstdc++.x86_64', state: 'present' }
- { name: 'libstdc++-devel.x86_64', state: 'present' }
- { name: 'compat-libstdc++-33.i686', state: 'present' }
- { name: 'compat-libstdc++-33.x86_64', state: 'present' }
- { name: 'compat-libstdc++-296-2.96-144.el6.i686', state: 'present' }
- { name: 'pam.i686', state: 'present' }
- { name: 'pam.x86_64', state: 'present' }
- { name: 'gtk2.i686', state: 'present' }
- { name: 'gtk2.x86_64', state: 'present' }
- { name: 'xorg-x11-xauth.x86_64', state: 'present' }
- { name: 'dos2unix', state: 'present' }
The command
Checking on subset of servers:# ansible-playbook add_packages.yml --check -i hosts --limit test_machines
Running:
# ansible-playbook add_packages.yml -i hosts
Comments