ansible-role-puppet_client/tasks/configure.yml

170 lines
4.2 KiB
YAML
Raw Normal View History

2022-10-11 09:19:08 +02:00
---
2022-10-24 11:55:55 +02:00
- name: Initialize puppet agent command
set_fact:
puppet_agent_cmd: false
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 12:14:55 +02:00
- name: Show puppet agent stats
debug:
msg: "{{ puppet_agent }}"
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-24 11:55:55 +02:00
- puppet_agent.stat.executable
- not puppet_agent.stat.isdir
2022-10-11 09:19:08 +02:00
2022-10-24 11:55:55 +02:00
# Not found expected path trying to find with the command which
2022-10-24 11:59:29 +02:00
- name: Find puppet agent with which command
2022-10-24 11:18:13 +02:00
shell: which puppet
2022-10-24 11:55:55 +02:00
register: puppet_which
2022-10-24 11:59:29 +02:00
failed_when: puppet_which.rc == 127
2022-10-24 11:18:13 +02:00
when:
2022-10-24 11:55:55 +02:00
- not puppet_agent_cmd
2022-10-24 11:33:49 +02:00
2022-10-24 11:55:55 +02:00
- name: Show puppet_which
2022-10-24 11:33:49 +02:00
debug:
2022-10-24 11:55:55 +02:00
msg: "{{ puppet_which }}"
when:
- not puppet_agent_cmd
- name: Get puppet command stats
stat:
2022-10-24 12:23:28 +02:00
path: "{{ puppet_which.stdout }}"
2022-10-24 11:55:55 +02:00
register: puppet_which_stat
when:
- not puppet_agent_cmd
- name: Set puppet agent command (from which)
set_fact:
puppet_agent_cmd: "{{ puppet_which.stdout }}"
2022-10-24 11:33:49 +02:00
when:
2022-10-24 11:55:55 +02:00
- puppet_which_stat.stat.exists
- not puppet_which_stat.stat.isdir
- puppet_which_stat.stat.executable
2022-10-21 20:21:51 +02:00
2022-10-24 11:55:55 +02:00
# Not found from command which trying to find with the command whereis
2022-10-24 11:59:29 +02:00
- name: Find puppet agent with whereis command
2022-10-24 11:18:13 +02:00
shell: "whereis -b puppet | awk 'BEGIN {FS=\": \"} {print($2)}'"
2022-10-24 11:55:55 +02:00
register: puppet_whereis
failed_when: puppet_whereis.rc == 127
2022-10-21 20:21:51 +02:00
when:
2022-10-24 11:55:55 +02:00
- not puppet_agent_cmd
2022-10-21 20:21:51 +02:00
2022-10-24 11:55:55 +02:00
- name: Show puppet_whereis
2022-10-24 11:22:57 +02:00
debug:
2022-10-24 11:55:55 +02:00
msg: "{{ puppet_whereis }}"
2022-10-24 11:22:57 +02:00
when:
2022-10-24 11:55:55 +02:00
- not puppet_agent_cmd
2022-10-24 11:22:57 +02:00
2022-10-24 11:55:55 +02:00
- name: Get puppet command stats
stat:
2022-10-24 12:23:28 +02:00
path: "{{ puppet_whereis.stdout }}"
2022-10-24 11:55:55 +02:00
register: puppet_whereis_stat
2022-10-24 11:18:13 +02:00
when:
2022-10-24 11:55:55 +02:00
- not puppet_agent_cmd
2022-10-24 11:18:13 +02:00
- name: Set puppet agent command (from which)
2022-10-21 20:21:51 +02:00
set_fact:
2022-10-24 11:55:55 +02:00
puppet_agent_cmd: "{{ puppet_whereis.stdout }}"
2022-10-24 11:18:13 +02:00
when:
2022-10-24 11:55:55 +02:00
- puppet_whereis_stat.stat.exists
- not puppet_whereis_stat.stat.isdir
- puppet_whereis_stat.stat.executable
2022-10-11 09:19:08 +02:00
2022-10-24 11:55:55 +02:00
# End section finding puppet command
2022-10-24 11:22:57 +02:00
- name: Link agent to /usr/local/bin
file:
state: link
dest: /usr/local/bin/puppet
src: "{{ puppet_agent_cmd }}"
2022-10-11 09:19:08 +02:00
- name: Obtain puppet configuration directory
2022-10-24 11:22:57 +02:00
shell: "/usr/local/bin/puppet 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:22:57 +02:00
shell: "/usr/local/bin/puppet 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:22:57 +02:00
job: "/usr/local/bin/puppet agent -t"
2022-10-11 09:19:08 +02:00
minute: '30'
when: "'WSL' in ansible_facts['kernel']"