Pause with prompt in loop - not prompting - 1.9.2

58 views
Skip to first unread message

Craig Moynes

unread,
Jul 29, 2015, 2:58:06 PM7/29/15
to Ansible Project
Hi,
  Just getting started with Ansible (1.9.2) and trying to get a playbook configured to deploy the latest version of our developers code.

What I wanted to do was loop through the property files from the source, and if there was a difference (by md5 comparison) prompt the user that they should manually verify and confirm. The reason for this is that different environments (lower test environments, production environments) may have had optimizations that I don't want to overwrite blindly - or skip and miss a change that should be deployed.

Even logging it at the end of the run would work from my perspective.

The following runs against a list of hosts (2 currently):
- hosts: webservice
  vars:
    local_path: /tmp/webservice-latest
    tomcat_dest_path: /opt/tomcat/webapps
    shared_classes_path: /opt/tomcat/shared/classes

    webservice_files: [
     {
      sample_name: wrapper.properties.sample,
      name: wrapper.properties,
      src: "{{local_path}}/conf",
      dest: "{{shared_classes_path}}"
     }
    ]

 tasks:

    - name: Get local stat of all webapp files
      become: no
      local_action: stat path="{{item.src}}/{{item.sample_name}}"
      with_items:
        - "{{webservice_files}}"
      register: local

    - name: Get remote stat of all the webapp files
      action: stat path="{{item.dest}}/{{item.name}}"
      with_items:
        - "{{webservice_files}}"
      register: remote

   - name: "Debug file stat for both local and remote - True"
      debug: msg="Stat should be True {{item.1.stat.path}}:{{item.1.stat.md5}} {{item.2.stat.path}}:{{item.2.stat.md5}}"
      when: '"{{item.2.stat.exists}}" == "True" and "{{item.1.stat.md5}}" != "{{item.2.stat.md5|default}}"'
      with_together:
        - "{{webservice_files}}"
        - "{{local.results}}"
        - "{{remote.results}}"

    # if the property files do exist, then we need to tell the user
    # and let them sort it out
    - name: Compare md5 of webservice files that do exist, prompt if different
      pause: prompt="Files are different - manually review (enter to continue)"
      when: '"{{item.2.stat.exists}}" == "True" and "{{item.1.stat.md5}}" != "{{item.2.stat.md5|default}}"'
      with_together:
        - "{{webservice_files}}"
        - "{{local.results}}"
        - "{{remote.results}}"

Test Scenario:
For my test the remote file on server1 is different than the local file, the remote file on server2 is identical.

Results:
I can see the debug line skipped for server2, and displayed for server1 which is correct.

The issue is that I only see the action skipped for server2, for server1 I don't get a prompt or a notification that it was skipped.  It just silently skips it.

Any suggestions?

I am thinking that pause does not work when used within a loop (although not documented here - http://docs.ansible.com/ansible/pause_module.html).

Even if I template the different environments property files, if someone has made a change I would prefer to at least notify the person deploying that there is an unexpected change in one of the files.


Cheers,
  Craig

Craig Moynes

unread,
Jul 31, 2015, 11:11:56 AM7/31/15
to Ansible Project, craig....@gmail.com
Anyone have any ideas?
Reply all
Reply to author
Forward
0 new messages