How to do best organization of install and delete in the same ansible playbook?

20 views
Skip to first unread message

Valeriy Solovyov

unread,
Mar 9, 2015, 11:01:04 AM3/9/15
to ansible...@googlegroups.com
Hello,
I try to figure how I must to construct an ansible playbooks with install/delete commands where it's variable changes. 
For example  apt_repository,apt,yum... where state=present -> installed and state=absent --> deleted

If I create two ansible playbooks: delete.yml and install.yml. There are may be problem's like:
I added to installation someting, but don't change deletion

Example:

install.yml:

    ---
    - name: Add x2go repository
      apt_repository: repo='deb http://ppa.launchpad.net/x2go/stable/ubuntu precise main' state=present
      apt_repository: repo='deb-src http://ppa.launchpad.net/x2go/stable/ubuntu precise main' state=present
      when: ansible_os_family == "Debian"
      tags:
        - remote-access-x2go
    - name: Install x2go application
      apt: name=x2goserver update_cache=yes state=present
      apt: name=x2goserver-xsession update_cache=no state=present
      when: ansible_os_family == "Debian"
      tags:
        - remote-access-x2go


delete.yml:

    ---
    - name: Add x2go repository
      apt_repository: repo='deb http://ppa.launchpad.net/x2go/stable/ubuntu precise main' state=absent
      apt_repository: repo='deb-src http://ppa.launchpad.net/x2go/stable/ubuntu precise main' state=present
      when: ansible_os_family == "Debian"
      tags:
        - remote-access-x2go
    - name: Install x2go application
      apt: name=x2goserver update_cache=yes state=absent
      apt: name=x2goserver-xsession update_cache=no state=absent
      when: ansible_os_family == "Debian"
      tags:
        - remote-access-x2go

Reply all
Reply to author
Forward
0 new messages