Includes with conditionals are implemented by including all the steps and applying the conditional to each included task.
You will get skipped messages. Often a better solution is using the group_by module to create a dynamic group, and then applying that config to just the hosts that match. This almost always produces cleaner output and is used often to apply different configs based on OS. http://docs.ansible.com/group_by_module.html On Wed, Jun 11, 2014 at 12:52 PM, Derrick Bryant <[email protected]> wrote: > Hello, > > I'm running in to an issue with conditional includes. I'm trying to create > an automatic rollback procedure for one of my playbooks which attempts to > deploy new versions of our company software. I'm using includes to abstract > the common roll back tasks to separate YAML files in a directory called > "rollback". I've included a small sample of the playbook below which > includes "rollback/exit.yml" when the result of the previous task failed. > What seems to happen is that ansible includes the tasks from the > rollback/exit.yml file and applies the "when: result|failed" condition to > every task in the included yaml file. This produces the desired result but > does print out a bunch of "skipped" messages as shown below. Is there a way > to tell ansible to only include the tasks if the previous task failed or to > not show the skipped tasks? Is there a better way to accomplish what I'm > trying to do? > > > I'm using a version of the command below to run the playbook (filename of > playbook changed): > > ansible-playbook playbooks/company_app.yml -i playbooks/hosts --tags >> "testing" >> >> > playbooks/company_app.yml > > --- >> - hosts: all >> vars: >> RPM_NAME: 'company_app_pacakge_name' >> remote_user: ansible >> sudo: yes >> #accelerate: true >> tasks: >> - name: Installing new RPM >> yum: "name={{ RPM_NAME }} state=present" >> ignore_errors: true >> tags: >> - testing >> register: result >> - include: rollback/exit.yml >> when: result|failed >> <<snip>> >> >> > playbooks/rollback/exit.yml > --- > - fail: msg="The company_app deployment failed." > tags: > - testing > > Ansible version: > $ ansible-playbook --version > ansible-playbook 1.6.3 > > Skipped message: > > [ansible@master01 ~]$ ansible-playbook playbooks/company_app.yml -i > playbooks/hosts --tags "testing" > > PLAY [all] > ******************************************************************** > > GATHERING FACTS > *************************************************************** > ok: [ansible_node] > > TASK: [Installing new RPM] > **************************************************** > ok: [ansible_node] > > TASK: [fail msg="The company_app deployment failed."] > **************************** > skipping: [ansible_node] > > > Thanks for the help, > Derrick > > -- > You received this message because you are subscribed to the Google Groups > "Ansible Project" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/ansible-project/7f43cbe3-58fc-4384-bc3f-64dd86e14714%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/7f43cbe3-58fc-4384-bc3f-64dd86e14714%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgza2-K-N0K%2BHxy%3DQb2E%2BvPg9a6G2XUngecnRymZkUkB2g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
