Sunday, April 30, 2017

Ansible - How to Install or Remove Multiple Packages

OS: CentOS 7/Red Hat 7

An exmple of installing or removing multiple package using with_items

main.yml:

- hosts: docker-host

  tasks:
    - name: Remove old versions of Docker
      yum: pkg={{item}} state=absent
      with_items:
        - docker
        - docker-common
        - container-selinux
        - docker-selinux
        - docker-engine

Then from the command line:
$ ansible-playbook -s main.yml

PLAY [dashboard-dev] ***********************************************************

TASK [setup] *******************************************************************
ok: [10.0.0.1]

TASK [Remove old versions of Docker] *******************************************
changed: [10.0.0.1] => (item=[u'docker', u'docker-common', u'container-selinux', u'docker-selinux', u'docker-engine', u'kdocker'])

PLAY RECAP *********************************************************************
10.0.0.1                : ok=2    changed=1    unreachable=0    failed=0

No comments: