summaryrefslogtreecommitdiff
path: root/tasks/main.yml
blob: 08362405550303b782c700f008171b25009cbd74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
- 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() }}"

  when: copy_hieradata

- block:
  - name: copy puppet modules
    synchronize:
      src: "{{ manifest_base }}/{{ puppet_environment }}"
      dest: "{{ manifest_base }}"

  - name: ensure hieradata manifest link is present
    file:
      src: "{{ hieradata }}"
      dest: "{{ manifest_base }}/hieradata"
      state: link
    when: copy_hieradata

  - name: copy system puppet modules
    synchronize:
      src: /etc/puppet/modules
      dest: /etc/puppet

  when:
  - copy_puppet
  - manifest_base is defined

- name: setup config files
  when: manage_config|bool
  include: config.yml

- block:
  - 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) }}"
      logdest: "{{ puppet_logdest|default(omit) }}"
      environment: "{{ puppet_environment|default(omit) }}"
      noop: "{{ puppet_noop|default(omit) }}"
      debug: "{{ puppet_debug|default(omit) }}"
- always:
  - 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: 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: 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 and puppet_report_as is defined