Install Packages using Ansible

From Knowledge Center
Jump to: navigation, search

Introduction

We will be using Ansible to Install Packages

Inventory

[admin]
localhost

[new]
docker-node-1
glusterfs-node-1
glusterfs-node-2
elasticsearch-node-1
elasticsearch-node-2

[admin:vars]
location_country="South Africa"
location_city="Cape Town"

[new:vars]
ansible_python_interpreter=/usr/bin/python3
location=europe

Playbook

Using APT for Debian Systems:

---
- hosts: all
  tasks:
  - name: Install Packages
    apt: name={{ item }} state=latest update_cache=yes
    with_items:
      - ntp
      - python
      - tcpdump
      - wget
      - openssl
      - curl

Running the Playbook

$ ansible-playbook -i inventory.ini packages.yml

PLAY [all] ***********************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************
ok: [glusterfs-node-2]
ok: [glusterfs-node-1]
ok: [docker-node-1]
ok: [elasticsearch-node-1]
ok: [elasticsearch-node-2]
ok: [localhost]

TASK [Install Packages] **********************************************************************************************************************************************************************************
ok: [docker-node-1] => (item=[u'ntp', u'python', u'tcpdump', u'wget', u'openssl', u'curl'])
ok: [elasticsearch-node-1] => (item=[u'ntp', u'python', u'tcpdump', u'wget', u'openssl', u'curl'])
ok: [glusterfs-node-1] => (item=[u'ntp', u'python', u'tcpdump', u'wget', u'openssl', u'curl'])
ok: [glusterfs-node-2] => (item=[u'ntp', u'python', u'tcpdump', u'wget', u'openssl', u'curl'])
ok: [elasticsearch-node-2] => (item=[u'ntp', u'python', u'tcpdump', u'wget', u'openssl', u'curl'])
changed: [localhost] => (item=[u'ntp', u'python', u'tcpdump', u'wget', u'openssl', u'curl'])

PLAY RECAP ***********************************************************************************************************************************************************************************************
docker-node-1              : ok=2    changed=0    unreachable=0    failed=0
elasticsearch-node-1       : ok=2    changed=0    unreachable=0    failed=0
elasticsearch-node-2       : ok=2    changed=0    unreachable=0    failed=0
glusterfs-node-1           : ok=2    changed=0    unreachable=0    failed=0
glusterfs-node-2           : ok=2    changed=0    unreachable=0    failed=0
localhost                  : ok=2    changed=1    unreachable=0    failed=0