From 98b7ea710bd499ecbc2a7ccbb670d434f9168897 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Wed, 12 Sep 2018 13:07:01 -0700 Subject: [PATCH] Fix ansible block, always, when syntax Newer ansible (2.7) is far more picky about always blocks being a part of block blocks. This means you cannot have a set of when conditions apply to a standalone always block. Fix our use of this by putting our always block in the run puppet block then move the always tasks into a block of their own with a condition set. Change-Id: I50988b6b312e4d00b73ca4454e0420913d4ae181 --- tasks/main.yaml | 71 ++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/tasks/main.yaml b/tasks/main.yaml index 3f33757..cb00cd6 100644 --- a/tasks/main.yaml +++ b/tasks/main.yaml @@ -142,43 +142,42 @@ debug: "{{ puppet_debug|default(omit) }}" timeout: "{{ puppet_timeout|default(omit) }}" -- always: + always: + - block: + - name: find logs + shell: "ls -tr /var/lib/puppet/reports/{{ ansible_fqdn }}/*_puppetdb.json" + register: files + failed_when: files.stdout_lines|default("") == "" - - name: find logs - shell: "ls -tr /var/lib/puppet/reports/{{ ansible_fqdn }}/*_puppetdb.json" - register: files - failed_when: files.stdout_lines|default("") == "" + - name: set log filename + set_fact: puppet_logfile="{{ files.stdout_lines|sort|last }}" + when: "{{ files.stdout_lines|length > 0 }}" - - name: set log filename - set_fact: puppet_logfile="{{ files.stdout_lines|sort|last }}" - when: "{{ files.stdout_lines|length > 0 }}" + - name: create reports directory + file: + path: '/var/lib/puppet/reports/{{ ansible_fqdn }}' + owner: root + group: root + mode: 0755 + state: directory + delegate_to: localhost + when: "{{ files.stdout_lines|length > 0 }}" - - name: create reports directory - file: - path: '/var/lib/puppet/reports/{{ ansible_fqdn }}' - owner: root - group: root - mode: 0755 - state: directory - delegate_to: localhost - when: "{{ files.stdout_lines|length > 0 }}" + - name: fetch file + synchronize: + mode: pull + src: "{{ puppet_logfile }}" + dest: /var/lib/puppet/reports/{{ ansible_fqdn }} + when: "{{ files.stdout_lines|length > 0 }}" - - name: fetch file - synchronize: - mode: pull - src: "{{ puppet_logfile }}" - dest: /var/lib/puppet/reports/{{ ansible_fqdn }} - when: "{{ files.stdout_lines|length > 0 }}" - - - name: post facts - puppet_post_puppetdb: - puppetdb: "{{ puppetdb }}" - hostvars: "{{ hostvars[inventory_hostname] }}" - logfile: "{{ puppet_logfile }}" - whoami: "{{ puppet_report_as }}" - delegate_to: localhost - when: "{{ files.stdout_lines|length > 0 }}" - - when: - - puppetdb is defined - - puppet_report_as is defined + - name: post facts + puppet_post_puppetdb: + puppetdb: "{{ puppetdb }}" + hostvars: "{{ hostvars[inventory_hostname] }}" + logfile: "{{ puppet_logfile }}" + whoami: "{{ puppet_report_as }}" + delegate_to: localhost + when: "{{ files.stdout_lines|length > 0 }}" + when: + - puppetdb is defined + - puppet_report_as is defined