Update to use blocks from ansible 2.0
One of the cool shiny new features from ansible 2.0 are "blocks", which allow you to group like tasks. Change-Id: If0a7c07140db15c9ae7c1671e6181ac7a4553f25
This commit is contained in:
@@ -11,7 +11,7 @@ galaxy_info:
|
|||||||
# - Apache
|
# - Apache
|
||||||
# - CC-BY
|
# - CC-BY
|
||||||
license: Apache
|
license: Apache
|
||||||
min_ansible_version: 1.2
|
min_ansible_version: 2.0
|
||||||
#
|
#
|
||||||
# Below are all platforms currently available. Just uncomment
|
# Below are all platforms currently available. Just uncomment
|
||||||
# the ones that apply to your role. If you don't see your
|
# the ones that apply to your role. If you don't see your
|
||||||
|
|||||||
171
tasks/main.yml
171
tasks/main.yml
@@ -1,76 +1,74 @@
|
|||||||
---
|
---
|
||||||
- name: ensure hiera datadir
|
- block:
|
||||||
file:
|
- name: ensure hiera datadir
|
||||||
state: directory
|
file:
|
||||||
path: "{{ hieradata }}/{{ hieraenvironment }}"
|
state: directory
|
||||||
owner: root
|
path: "{{ hieradata }}/{{ hieraenvironment }}"
|
||||||
group: root
|
owner: root
|
||||||
mode: 0700
|
group: root
|
||||||
|
mode: 0700
|
||||||
|
|
||||||
|
- name: ensure hiera datadir - fqdn
|
||||||
|
file:
|
||||||
|
state: directory
|
||||||
|
path: "{{ hieradata }}/{{ hieraenvironment }}/fqdn"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0700
|
||||||
|
|
||||||
|
- name: ensure hiera datadir - group
|
||||||
|
file:
|
||||||
|
state: directory
|
||||||
|
path: "{{ hieradata }}/{{ hieraenvironment }}/group"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0700
|
||||||
|
|
||||||
|
- name: make file list
|
||||||
|
puppet_get_hiera_file_list:
|
||||||
|
fqdn: "{{ ansible_fqdn }}"
|
||||||
|
groups: "{{ hostvars[inventory_hostname].group_names }}"
|
||||||
|
delegate_to: localhost
|
||||||
|
register: hiera_file_paths
|
||||||
|
|
||||||
|
- name: find which files exist
|
||||||
|
stat:
|
||||||
|
path: "{{ hieradata }}/{{ hieraenvironment }}/{{ item }}"
|
||||||
|
register: st
|
||||||
|
with_items: hiera_file_paths.paths_dict.paths
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
|
- name: copy hiera files
|
||||||
|
when: item.1.stat.exists
|
||||||
|
copy:
|
||||||
|
src: "{{ hieradata }}/{{ hieraenvironment }}/{{ item.1.item }}"
|
||||||
|
dest: "{{ hieradata }}/{{ hieraenvironment }}/{{ item.1.item }}"
|
||||||
|
mode: 0600
|
||||||
|
with_together:
|
||||||
|
- hiera_file_paths.paths_dict.paths
|
||||||
|
- st.results
|
||||||
|
|
||||||
|
- name: ensure hieradata manifest link is present
|
||||||
|
file:
|
||||||
|
src: "{{ hieradata }}"
|
||||||
|
dest: "{{ manifest_base }}/hieradata"
|
||||||
|
state: link
|
||||||
|
|
||||||
when: copy_hieradata is defined and copy_hieradata
|
when: copy_hieradata is defined and copy_hieradata
|
||||||
|
|
||||||
- name: ensure hiera datadir - fqdn
|
- block:
|
||||||
file:
|
- name: copy puppet modules
|
||||||
state: directory
|
synchronize:
|
||||||
path: "{{ hieradata }}/{{ hieraenvironment }}/fqdn"
|
src: "{{ manifest_base }}/{{ hieraenvironment }}"
|
||||||
owner: root
|
dest: "{{ manifest_base }}"
|
||||||
group: root
|
|
||||||
mode: 0700
|
|
||||||
when: copy_hieradata is defined and copy_hieradata
|
|
||||||
|
|
||||||
- name: ensure hiera datadir - group
|
- name: copy system puppet modules
|
||||||
file:
|
synchronize:
|
||||||
state: directory
|
src: /etc/puppet/modules
|
||||||
path: "{{ hieradata }}/{{ hieraenvironment }}/group"
|
dest: /etc/puppet
|
||||||
owner: root
|
|
||||||
group: root
|
|
||||||
mode: 0700
|
|
||||||
when: copy_hieradata is defined and copy_hieradata
|
|
||||||
|
|
||||||
- name: make file list
|
|
||||||
puppet_get_hiera_file_list:
|
|
||||||
fqdn: "{{ ansible_fqdn }}"
|
|
||||||
groups: "{{ hostvars[inventory_hostname].group_names }}"
|
|
||||||
when: copy_hieradata is defined and copy_hieradata
|
|
||||||
delegate_to: localhost
|
|
||||||
register: hiera_file_paths
|
|
||||||
|
|
||||||
- name: find which files exist
|
|
||||||
stat:
|
|
||||||
path: "{{ hieradata }}/{{ hieraenvironment }}/{{ item }}"
|
|
||||||
register: st
|
|
||||||
with_items: hiera_file_paths.paths_dict.paths
|
|
||||||
delegate_to: localhost
|
|
||||||
when: copy_hieradata is defined and copy_hieradata
|
|
||||||
|
|
||||||
- name: copy hiera files
|
|
||||||
when: copy_hieradata is defined and copy_hieradata and item.1.stat.exists
|
|
||||||
copy:
|
|
||||||
src: "{{ hieradata }}/{{ hieraenvironment }}/{{ item.1.item }}"
|
|
||||||
dest: "{{ hieradata }}/{{ hieraenvironment }}/{{ item.1.item }}"
|
|
||||||
mode: 0600
|
|
||||||
with_together:
|
|
||||||
- hiera_file_paths.paths_dict.paths
|
|
||||||
- st.results
|
|
||||||
|
|
||||||
- name: copy puppet modules
|
|
||||||
synchronize:
|
|
||||||
src: "{{ manifest_base }}/{{ hieraenvironment }}"
|
|
||||||
dest: "{{ manifest_base }}"
|
|
||||||
when: copy_puppet is defined and copy_puppet and manifest_base is defined
|
when: copy_puppet is defined and copy_puppet and manifest_base is defined
|
||||||
|
|
||||||
- name: copy system puppet modules
|
|
||||||
synchronize:
|
|
||||||
src: /etc/puppet/modules
|
|
||||||
dest: /etc/puppet
|
|
||||||
when: copy_puppet is defined and copy_puppet and manifest_base is defined
|
|
||||||
|
|
||||||
- name: ensure hieradata manifest link is present
|
|
||||||
file:
|
|
||||||
src: "{{ hieradata }}"
|
|
||||||
dest: "{{ manifest_base }}/hieradata"
|
|
||||||
state: link
|
|
||||||
when: copy_hieradata is defined and copy_hieradata
|
|
||||||
|
|
||||||
- name: run puppet
|
- name: run puppet
|
||||||
puppet:
|
puppet:
|
||||||
puppetmaster: "{{ puppetmaster|default(omit) }}"
|
puppetmaster: "{{ puppetmaster|default(omit) }}"
|
||||||
@@ -79,28 +77,27 @@
|
|||||||
facts: "{{ facts|default(omit) }}"
|
facts: "{{ facts|default(omit) }}"
|
||||||
facter_basename: "{{ facter_basename|default(omit) }}"
|
facter_basename: "{{ facter_basename|default(omit) }}"
|
||||||
|
|
||||||
- name: find logs
|
- block:
|
||||||
shell: "ls -tr /var/lib/puppet/reports/{{ ansible_fqdn }}/*_puppetdb.json"
|
- name: find logs
|
||||||
register: files
|
shell: "ls -tr /var/lib/puppet/reports/{{ ansible_fqdn }}/*_puppetdb.json"
|
||||||
when: puppetdb is defined
|
register: files
|
||||||
|
|
||||||
- name: set log filename
|
- name: set log filename
|
||||||
set_fact: puppet_logfile="{{ files.stdout_lines|sort|last }}"
|
set_fact: puppet_logfile="{{ files.stdout_lines|sort|last }}"
|
||||||
when: puppetdb is defined
|
|
||||||
|
|
||||||
- name: fetch file
|
- name: fetch file
|
||||||
synchronize:
|
synchronize:
|
||||||
mode: pull
|
mode: pull
|
||||||
src: "{{ puppet_logfile }}"
|
src: "{{ puppet_logfile }}"
|
||||||
dest: /var/lib/puppet/reports/{{ ansible_fqdn }}
|
dest: /var/lib/puppet/reports/{{ ansible_fqdn }}
|
||||||
when: puppetdb is defined
|
|
||||||
|
- name: post facts
|
||||||
|
puppet_post_puppetdb:
|
||||||
|
puppetdb: "{{ puppetdb }}"
|
||||||
|
hostvars: "{{ hostvars[inventory_hostname] }}"
|
||||||
|
logfile: "{{ puppet_logfile }}"
|
||||||
|
whoami: "{{ ansible_fqdn }}"
|
||||||
|
delegate_to: localhost
|
||||||
|
connection: local
|
||||||
|
|
||||||
- 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
|
when: puppetdb is defined
|
||||||
|
|||||||
Reference in New Issue
Block a user