Ansible role for running puppet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.yml 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. ---
  2. - block:
  3. - name: ensure hiera directory
  4. file:
  5. state: directory
  6. path: "{{ hieradata }}/{{ puppet_environment }}/{{ item }}"
  7. owner: root
  8. group: root
  9. mode: 0700
  10. with_items:
  11. - fqdn
  12. - group
  13. - name: make file list
  14. puppet_get_hiera_file_list:
  15. fqdn: "{{ ansible_fqdn }}"
  16. groups: "{{ hostvars[inventory_hostname].group_names }}"
  17. location: "{{ hieradata }}/{{ puppet_environment }}"
  18. delegate_to: localhost
  19. register: hiera_file_paths
  20. - name: copy hiera files
  21. copy:
  22. src: "{{ item }}"
  23. dest: "{{ item }}"
  24. mode: 0600
  25. with_items: "{{ hiera_file_paths.paths|default() }}"
  26. when: copy_hieradata
  27. - block:
  28. - name: copy puppet modules
  29. synchronize:
  30. src: "{{ manifest_base }}/{{ puppet_environment }}"
  31. dest: "{{ manifest_base }}"
  32. - name: ensure hieradata manifest link is present
  33. file:
  34. src: "{{ hieradata }}"
  35. dest: "{{ manifest_base }}/hieradata"
  36. state: link
  37. when: copy_hieradata
  38. - name: copy system puppet modules
  39. synchronize:
  40. src: /etc/puppet/modules
  41. dest: /etc/puppet
  42. when:
  43. - copy_puppet
  44. - manifest_base is defined
  45. - name: setup config files
  46. when: manage_config|bool
  47. include: config.yml
  48. - block:
  49. - name: run puppet
  50. puppet:
  51. puppetmaster: "{{ puppetmaster|default(omit) }}"
  52. manifest: "{{ manifest|default(omit) }}"
  53. show_diff: "{{ show_diff|default(false) }}"
  54. facts: "{{ facts|default(omit) }}"
  55. facter_basename: "{{ facter_basename|default(omit) }}"
  56. logdest: "{{ puppet_logdest|default(omit) }}"
  57. environment: "{{ puppet_environment|default(omit) }}"
  58. noop: "{{ puppet_noop|default(omit) }}"
  59. debug: "{{ puppet_debug|default(omit) }}"
  60. - always:
  61. - name: find logs
  62. shell: "ls -tr /var/lib/puppet/reports/{{ ansible_fqdn }}/*_puppetdb.json"
  63. register: files
  64. failed_when: files.stdout_lines|default("") == ""
  65. - name: set log filename
  66. set_fact: puppet_logfile="{{ files.stdout_lines|sort|last }}"
  67. when: "{{ files.stdout_lines|length > 0 }}"
  68. - name: create reports directory
  69. file: path=/var/lib/puppet/reports/{{ ansible_fqdn }} owner=root group=root mode=0755 state=directory
  70. delegate_to: localhost
  71. when: "{{ files.stdout_lines|length > 0 }}"
  72. - name: fetch file
  73. synchronize:
  74. mode: pull
  75. src: "{{ puppet_logfile }}"
  76. dest: /var/lib/puppet/reports/{{ ansible_fqdn }}
  77. when: "{{ files.stdout_lines|length > 0 }}"
  78. - name: post facts
  79. puppet_post_puppetdb:
  80. puppetdb: "{{ puppetdb }}"
  81. hostvars: "{{ hostvars[inventory_hostname] }}"
  82. logfile: "{{ puppet_logfile }}"
  83. whoami: "{{ puppet_report_as }}"
  84. delegate_to: localhost
  85. when: "{{ files.stdout_lines|length > 0 }}"
  86. when: puppetdb is defined and puppet_report_as is defined