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
This commit is contained in:
Clark Boylan 2018-09-12 13:07:01 -07:00
parent 7b47277e3e
commit 98b7ea710b
1 changed files with 35 additions and 36 deletions

View File

@ -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