ansible-role-puppet_client/tasks/configure.yml

173 lines
4.3 KiB
YAML

---
- name: Initialize puppet agent command
set_fact:
puppet_agent_cmd: false
- name: Check if puppet agent is present
stat:
path: /opt/puppetlabs/bin/puppet
register: puppet_agent
- name: Show puppet agent stats
debug:
msg: "{{ puppet_agent }}"
- name: Set puppet agent command
set_fact:
puppet_agent_cmd: /opt/puppetlabs/bin/puppet
when:
- puppet_agent.stat.exists
- puppet_agent.stat.executable
- not puppet_agent.stat.isdir
# Not found expected path trying to find with the command which
- name: Find puppet agent with which command
shell: which puppet
register: puppet_which
failed_when: puppet_which.rc == 127
when:
- not puppet_agent_cmd
- name: Show puppet_which
debug:
msg: "{{ puppet_which }}"
when:
- not puppet_agent_cmd
- name: Get puppet command stats
stat:
path: "{{ puppet_which.stdout }}"
register: puppet_which_stat
when:
- not puppet_agent_cmd
- name: Set puppet agent command (from which)
set_fact:
puppet_agent_cmd: "{{ puppet_which.stdout }}"
when:
- "'stat' in puppet_which_stat"
- puppet_which_stat.stat.exists
- not puppet_which_stat.stat.isdir
- puppet_which_stat.stat.executable
# Not found from command which trying to find with the command whereis
- name: Find puppet agent with whereis command
shell: "whereis -b puppet | awk 'BEGIN {FS=\": \"} {print($2)}'"
register: puppet_whereis
failed_when: puppet_whereis.rc == 127
when:
- not puppet_agent_cmd
- name: Show puppet_whereis
debug:
msg: "{{ puppet_whereis }}"
when:
- not puppet_agent_cmd
- name: Get puppet command stats
stat:
path: "{{ puppet_whereis.stdout }}"
register: puppet_whereis_stat
when:
- not puppet_agent_cmd
- name: Set puppet agent command (from whereis)
set_fact:
puppet_agent_cmd: "{{ puppet_whereis.stdout }}"
when:
- "'stat' in puppet_whereis_stat"
- puppet_whereis_stat.stat.exists
- not puppet_whereis_stat.stat.isdir
- puppet_whereis_stat.stat.executable
# End section finding puppet command
- name: Link agent to /usr/local/bin
file:
state: link
dest: /usr/local/bin/puppet
src: "{{ puppet_agent_cmd }}"
when:
- puppet_agent_cmd != '/usr/local/bin/puppet'
- name: Obtain puppet configuration directory
shell: "/usr/local/bin/puppet config print confdir"
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
shell: "/usr/local/bin/puppet agent -t"
when: run_puppet
- name: Ensure puppet agent service is enabled and started
systemd:
name: puppet
enabled: true
state: started
masked: false
when: "'WSL' not in ansible_facts['kernel']"
- name: Ensure puppet agent cron exists (WSL only)
cron:
name: puppet agent
job: "/usr/local/bin/puppet agent -t"
minute: '30'
when: "'WSL' in ansible_facts['kernel']"