Monty Taylor d0854ce5d5 Properly suppress undefined warning
Although there is no harm in this case, the task in question has a
with_items on a variable that is not set because the previous task did
not run. In this case, it did not run because it's in a block with a
when that did not match - but in the context of a task, when is applied
after with_items and is applied to each with_item, rather than to the
task as a whole. To make the task complete, add a |default() jinja
filter so that the undefined variable is replaced with a defined but
empty value.

Change-Id: I2029b7cac3634a5fe7232f6f823e803e1f4250e6
2016-01-19 08:03:57 -05:00

85 lines
2.1 KiB
YAML

---
- block:
- name: ensure hiera directory
file:
state: directory
path: "{{ hieradata }}/{{ puppet_environment }}/{{ item }}"
owner: root
group: root
mode: 0700
with_items:
- fqdn
- group
- name: make file list
puppet_get_hiera_file_list:
fqdn: "{{ ansible_fqdn }}"
groups: "{{ hostvars[inventory_hostname].group_names }}"
location: "{{ hieradata }}/{{ puppet_environment }}"
delegate_to: localhost
register: hiera_file_paths
- name: copy hiera files
copy:
src: "{{ item }}"
dest: "{{ item }}"
mode: 0600
with_items: hiera_file_paths.paths|default()
- name: ensure hieradata manifest link is present
file:
src: "{{ hieradata }}"
dest: "{{ manifest_base }}/hieradata"
state: link
when: manifest_base is defined
when: copy_hieradata
- block:
- name: copy puppet modules
synchronize:
src: "{{ manifest_base }}/{{ puppet_environment }}"
dest: "{{ manifest_base }}"
- name: copy system puppet modules
synchronize:
src: /etc/puppet/modules
dest: /etc/puppet
when:
- copy_puppet
- manifest_base is defined
- name: run puppet
puppet:
puppetmaster: "{{ puppetmaster|default(omit) }}"
manifest: "{{ manifest|default(omit) }}"
show_diff: "{{ show_diff|default(false) }}"
facts: "{{ facts|default(omit) }}"
facter_basename: "{{ facter_basename|default(omit) }}"
- block:
- name: find logs
shell: "ls -tr /var/lib/puppet/reports/{{ ansible_fqdn }}/*_puppetdb.json"
register: files
- name: set log filename
set_fact: puppet_logfile="{{ files.stdout_lines|sort|last }}"
- name: fetch file
synchronize:
mode: pull
src: "{{ puppet_logfile }}"
dest: /var/lib/puppet/reports/{{ ansible_fqdn }}
- name: post facts
puppet_post_puppetdb:
puppetdb: "{{ puppetdb }}"
hostvars: "{{ hostvars[inventory_hostname] }}"
logfile: "{{ puppet_logfile }}"
whoami: "{{ ansible_fqdn }}"
delegate_to: localhost
connection: local
when: puppetdb is defined