Nice alternative to 'tags' for restricting change scope in a playbook

25 views
Skip to first unread message

Russell Briggs

unread,
Jan 14, 2015, 2:13:15 PM1/14/15
to ansible...@googlegroups.com
Hi All

First off, I LOVE ansible, its awesome! Really didn't like puppet when I tried it.

Just wanted to share a nice pattern I found for making it easy to run only part of a playbook, without having to remember which tags to use with the --tags option. (apologies if something similar has been posted before!)

With the below code at the top of the playbook, when you run it with ansible-playbook, you are first presented with an options menu asking you what you want to do :)


- name: My awesome playbook with options menu :)

  vars_prompt:
    update_option: |
      This playbook updates LIVE SYSTEMS. Use with caution!

      Please enter one of the following options to perform the update:
        app_update  - check / update application software only
        nginx       - check / update nginx configuration
        backup      - check / update backup configuration
        all         - check / update all items

      Or press CTRL+C to Cancel!

  roles:
  - { role: my_app_role,              when: "update_option in ['app_update', 'all']" }
  - { role: my_app_other_role,        when: "update_option in ['app_update', 'all']" }
  - { role: nginx,                    when: "update_option in ['nginx', 'all']" }
  - { role: app_backup,               when: "update_option in ['backup', 'all']" }

Cheers all!

Russell Briggs
(Junari Ltd)
Reply all
Reply to author
Forward
0 new messages