2022-10-11 09:19:08 +02:00
|
|
|
---
|
2022-10-24 11:18:13 +02:00
|
|
|
- name: Check if puppet agent is present
|
|
|
|
stat:
|
|
|
|
path: /opt/puppetlabs/bin/puppet
|
|
|
|
register: puppet_agent
|
2022-10-11 09:19:08 +02:00
|
|
|
|
2022-10-24 11:18:13 +02:00
|
|
|
- name: Link agent to /usr/local/bin
|
|
|
|
file:
|
|
|
|
state: link
|
|
|
|
dest: /usr/local/bin/puppet
|
|
|
|
src: /opt/puppetlabs/bin/puppet
|
|
|
|
when:
|
|
|
|
- puppet_agent.stat.exists
|
2022-10-11 09:19:08 +02:00
|
|
|
|
2022-10-24 11:18:13 +02:00
|
|
|
- name: Set puppet agent command
|
|
|
|
set_fact:
|
|
|
|
puppet_agent_cmd: /opt/puppetlabs/bin/puppet
|
|
|
|
when:
|
|
|
|
- puppet_agent.stat.exists
|
2022-10-11 09:19:08 +02:00
|
|
|
|
2022-10-24 11:18:13 +02:00
|
|
|
- name: Find puppet agent
|
|
|
|
shell: which puppet
|
|
|
|
register: puppet_script
|
|
|
|
failed_when: puppet_script.rc == 127
|
|
|
|
when:
|
|
|
|
- not puppet_agent.stat.exists
|
2022-10-21 20:21:51 +02:00
|
|
|
|
2022-10-24 11:18:13 +02:00
|
|
|
- name: Find puppet agent with whereis
|
|
|
|
shell: "whereis -b puppet | awk 'BEGIN {FS=\": \"} {print($2)}'"
|
|
|
|
register: puppet_script
|
|
|
|
failed_when: puppet_script.rc == 127
|
2022-10-21 20:21:51 +02:00
|
|
|
when:
|
2022-10-24 11:18:13 +02:00
|
|
|
- not puppet_agent.stat.exists
|
|
|
|
- puppet_script.stdout == ''
|
2022-10-21 20:21:51 +02:00
|
|
|
|
2022-10-24 11:18:13 +02:00
|
|
|
- name: Check puppet agent was found
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- "'stdout' in puppet_script"
|
|
|
|
- puppet_script.stdout != ""
|
|
|
|
- puppet_script.rc == 0
|
|
|
|
when:
|
|
|
|
- not puppet_agent.stat.exists
|
|
|
|
|
|
|
|
- name: Set puppet agent command (from which)
|
2022-10-21 20:21:51 +02:00
|
|
|
set_fact:
|
2022-10-24 11:18:13 +02:00
|
|
|
puppet_agent_cmd: "{{ puppet_script.stdout }}"
|
|
|
|
when:
|
|
|
|
- not puppet_agent.stat.exists
|
2022-10-11 09:19:08 +02:00
|
|
|
|
|
|
|
- name: Obtain puppet configuration directory
|
2022-10-24 11:18:13 +02:00
|
|
|
shell: "{{ puppet_agent_cmd }} config print confdir"
|
2022-10-11 09:19:08 +02:00
|
|
|
register: current_puppet_confdir
|
|
|
|
|
|
|
|
- name: Ensure puppet server is configured in main section
|
|
|
|
ini_file:
|
|
|
|
path: "{{ current_puppet_confdir.stdout }}/puppet.conf"
|
|
|
|
section: main
|
|
|
|
option: server
|
|
|
|
value: "{{ puppet_server }}"
|
|
|
|
backup: yes
|
|
|
|
create: yes
|
|
|
|
mode: 0644
|
|
|
|
|
|
|
|
- name: Ensure puppet server is configured in master section
|
|
|
|
ini_file:
|
|
|
|
path: "{{ current_puppet_confdir.stdout }}/puppet.conf"
|
|
|
|
section: master
|
|
|
|
option: server
|
|
|
|
value: "{{ puppet_server }}"
|
|
|
|
backup: yes
|
|
|
|
create: yes
|
|
|
|
mode: 0644
|
|
|
|
|
|
|
|
- name: Ensure puppet port is configured in main section
|
|
|
|
ini_file:
|
|
|
|
path: "{{ current_puppet_confdir.stdout }}/puppet.conf"
|
|
|
|
section: main
|
|
|
|
option: serverport
|
|
|
|
value: "{{ puppet_server_port }}"
|
|
|
|
backup: yes
|
|
|
|
create: yes
|
|
|
|
mode: 0644
|
|
|
|
|
|
|
|
- name: Ensure puppet port is configured in master section
|
|
|
|
ini_file:
|
|
|
|
path: "{{ current_puppet_confdir.stdout }}/puppet.conf"
|
|
|
|
section: master
|
|
|
|
option: port
|
|
|
|
value: "{{ puppet_server_port }}"
|
|
|
|
backup: yes
|
|
|
|
create: yes
|
|
|
|
mode: 0644
|
|
|
|
|
|
|
|
- name: Ensure puppet run interval is configured in main section
|
|
|
|
ini_file:
|
|
|
|
path: "{{ current_puppet_confdir.stdout }}/puppet.conf"
|
|
|
|
section: main
|
|
|
|
option: runinterval
|
|
|
|
value: "{{ puppet_runinterval }}"
|
|
|
|
backup: yes
|
|
|
|
create: yes
|
|
|
|
mode: 0644
|
|
|
|
|
|
|
|
- name: Ensure puppet run interval is configured in master section
|
|
|
|
ini_file:
|
|
|
|
path: "{{ current_puppet_confdir.stdout }}/puppet.conf"
|
|
|
|
section: master
|
|
|
|
option: runinterval
|
|
|
|
value: "{{ puppet_runinterval }}"
|
|
|
|
backup: yes
|
|
|
|
create: yes
|
|
|
|
mode: 0644
|
|
|
|
|
|
|
|
- name: Run puppet for the first time
|
2022-10-24 11:18:13 +02:00
|
|
|
shell: "{{ puppet_agent_cmd }} agent -t"
|
2022-10-11 09:19:08 +02:00
|
|
|
when: run_puppet
|
|
|
|
|
|
|
|
- name: Ensure puppet agent service is enabled and started
|
2022-10-21 20:27:41 +02:00
|
|
|
systemd:
|
2022-10-11 09:19:08 +02:00
|
|
|
name: puppet
|
2022-10-21 20:27:41 +02:00
|
|
|
enabled: true
|
2022-10-11 09:19:08 +02:00
|
|
|
state: started
|
2022-10-21 20:28:40 +02:00
|
|
|
masked: false
|
2022-10-11 09:19:08 +02:00
|
|
|
when: "'WSL' not in ansible_facts['kernel']"
|
|
|
|
|
|
|
|
- name: Ensure puppet agent cron exists (WSL only)
|
|
|
|
cron:
|
|
|
|
name: puppet agent
|
2022-10-24 11:18:13 +02:00
|
|
|
job: "{{ puppet_agent_cmd }} agent -t"
|
2022-10-11 09:19:08 +02:00
|
|
|
minute: '30'
|
|
|
|
when: "'WSL' in ansible_facts['kernel']"
|