Conditional continues to monitor result. Bug or Feature?

17 views
Skip to first unread message

Mike Schlottman

unread,
Oct 3, 2016, 9:14:39 PM10/3/16
to Ansible Project
I have a playbook that checks to see if ansible can ssh to a VM.  If it cannot, it assigns a role of deploy_vm_from_template to the host.  During the process of deploying the VM the host gets booted, the network is configured and I verify that ansible can ssh to the host before continuing with other roles.

Everything worked fine, until I decided I needed to restart sssd after verifying that I could ssh to the host.   What I found is that once, I could ssh to the host, every task in the role deploy_vm_from_template was skipped.   It appears that the "when: result|failed" triggers when "result" is updated in my until loop in the role.  I verified this by changing "result" in the playbook to "result_in_playbook" and the tasks after the until loop began running instead of being skipped.

My question, is this a bug or a feature?   This seems like it could be a very powerful feature.   It seems like result is a widely used variable.  Should I be using more unique variables to avoid this situation?


# From the playbook 
 pre_tasks:
    - name: "See if we can ssh to {{ inventory_hostname }} before attempting to build it"
      local_action: command ssh -o ConnectTimeout=10 servacct_ansible@{{ inventory_hostname }} hostname
      register: result
      ignore_errors: yes

  roles:
    - { role: deploy_vm_from_template, when: result|failed }


#From the role
    - name: "Wait for {{ inventory_hostname }} to recognize servacct_ansible account"
      register: result
      until: result.rc == 0
      retries: 30
      delay: 10

    - name: Test ping module
      ping:

Brian Coca

unread,
Feb 9, 2017, 10:58:09 PM2/9/17
to Ansible Project
skipping a task still activates 'register' so subsequent tasks can
check 'result|skipped' and be conditioned on that fact.


----------
Brian Coca
Reply all
Reply to author
Forward
0 new messages