0
votes

I have a playbook and for some unknown reason is failing with Ansible 2.2.1.0

Playbook tasks (last but one and the one that is failing)

   - name: Extract out tag string for {{ image }}
     shell: docker inspect -f "{{ '{{' }}.Id {{ '}}' }}" {{ tagged_image_full }} | awk -F ":" '{print $2}' | cut -c 1-12
     register: image_tag
     when: image is defined

   - name: Save {{ tagged_image_full }} image
     shell: docker save {{ tagged_image_full }} | gzip -c >> {{ save_path }}{{ image }}_{{ image_tag.stdout }}_{{ tag }}.tgz
     when: tagged_image_full is defined

The verbose output is

TASK [Extract out tag string for presence-insight] ***************************** changed: [docker01] => {"changed": true, "cmd": "docker inspect -f \"{{.Id }}\" presence-insight:origin_release_1_4_0-17 | awk -F \":\" '{print $2}' | cut -c 1-12", "delta": "0:00:00.025295", "end": "2017-04-11 15:17:13.800655", "rc": 0, "start": "2017-04-11 15:17:13.775360", "stderr": "", "stdout": "d0ca3e53a2ce", "stdout_lines": ["d0ca3e53a2ce"], "warnings": []}

TASK [Save presence-insight:origin_release_1_4_0-17 image] ********************* fatal: [docker01]: FAILED! => {"failed": true, "msg": "{u'cmd': u'docker inspect -f \"{{.Id }}\" presence-insight:origin_release_1_4_0-17 | awk -F \":\" \'{print $2}\' | cut -c 1-12', u'end': u'2017-04-11 15:17:13.800655', u'stdout': u'd0ca3e53a2ce', u'changed': True, u'start': u'2017-04-11 15:17:13.775360', u'delta': u'0:00:00.025295', u'stderr': u'', u'rc': 0, 'stdout_lines': [u'd0ca3e53a2ce'], u'warnings': []}: template error while templating string: unexpected '.'. String: docker inspect -f \"{{.Id }}\" presence-insight:origin_release_1_4_0-17 | awk -F \":\" '{print $2}' | cut -c 1-12"}

Why is Ansible trying to execute the previous tasks shell and not the shell instructions defined in the failing task?

Any clues?

1

1 Answers

0
votes

Looks like escaping changed with Ansible 2.2.1.0 at least when it comes to docker inspect command.

Here is the corrected task to extract out the Docker Image Id

   - name: Extract out tag string for {{ image }}
     shell: docker inspect -f \{\{'.Id'\}\} {{ tagged_image_full }} | awk -F ":" '{print $2}' | cut -c 1-12
     register: image_tag
     when: image is defined