manage finding puppet command

This commit is contained in:
Antonio J. Delgado 2022-10-24 12:18:13 +03:00
parent d300c922ca
commit 4254d8675a
3 changed files with 56 additions and 36 deletions

View file

@ -1,37 +1,55 @@
--- ---
- name: Obtain path to puppet binary using which - name: Check if puppet agent is present
shell: which puppet | true
register: which_puppet
- name: Show which_puppet
debug:
msg: "{{ which_puppet }}"
- name: Obtain path to puppet binary using whereis
shell: "whereis -b puppet | awk 'BEGIN {FS=\" \"} {print($2)}'"
register: which_puppet
when: which_puppet.stdout == ""
- name: Get puppet permissions
stat: stat:
path: "{{ which_puppet.stdout }}" path: /opt/puppetlabs/bin/puppet
register: which_puppet_stat register: puppet_agent
- name: Set fact for puppet path - name: Link agent to /usr/local/bin
set_fact: file:
puppet_cmd: "{{ which_puppet.stdout }}" state: link
dest: /usr/local/bin/puppet
src: /opt/puppetlabs/bin/puppet
when: when:
- which_puppet.stdout != "" - puppet_agent.stat.exists
- which_puppet_stat.stat.executable
- not which_puppet_stat.stat.isdir
- name: Set fact for puppet path to estimated path when not found - name: Set puppet agent command
set_fact: set_fact:
puppet_cmd: "/usr/local/bin/puppet" puppet_agent_cmd: /opt/puppetlabs/bin/puppet
when: which_puppet.stdout == "" or not which_puppet_stat.stat.executable or which_puppet_stat.stat.isdir when:
- puppet_agent.stat.exists
- name: Find puppet agent
shell: which puppet
register: puppet_script
failed_when: puppet_script.rc == 127
when:
- not puppet_agent.stat.exists
- name: Find puppet agent with whereis
shell: "whereis -b puppet | awk 'BEGIN {FS=\": \"} {print($2)}'"
register: puppet_script
failed_when: puppet_script.rc == 127
when:
- not puppet_agent.stat.exists
- puppet_script.stdout == ''
- 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)
set_fact:
puppet_agent_cmd: "{{ puppet_script.stdout }}"
when:
- not puppet_agent.stat.exists
- name: Obtain puppet configuration directory - name: Obtain puppet configuration directory
shell: "{{ puppet_cmd }} config print confdir" shell: "{{ puppet_agent_cmd }} config print confdir"
register: current_puppet_confdir register: current_puppet_confdir
- name: Ensure puppet server is configured in main section - name: Ensure puppet server is configured in main section
@ -95,7 +113,7 @@
mode: 0644 mode: 0644
- name: Run puppet for the first time - name: Run puppet for the first time
shell: "{{ puppet_cmd }} agent -t" shell: "{{ puppet_agent_cmd }} agent -t"
when: run_puppet when: run_puppet
- name: Ensure puppet agent service is enabled and started - name: Ensure puppet agent service is enabled and started
@ -109,6 +127,6 @@
- name: Ensure puppet agent cron exists (WSL only) - name: Ensure puppet agent cron exists (WSL only)
cron: cron:
name: puppet agent name: puppet agent
job: puppet agent -t job: "{{ puppet_agent_cmd }} agent -t"
minute: '30' minute: '30'
when: "'WSL' in ansible_facts['kernel']" when: "'WSL' in ansible_facts['kernel']"

View file

@ -4,9 +4,9 @@
name: name:
- ruby-full - ruby-full
- ruby-augeas - ruby-augeas
#- libaugeas0 # - libaugeas0
- libaugeas-dev - libaugeas-dev
#- augeas-tools # - augeas-tools
- name: Ensure Puppet agent gem is installed - name: Ensure Puppet agent gem is installed
gem: gem:
@ -57,7 +57,7 @@
section: main section: main
option: server option: server
value: "{{ puppet_server }}" value: "{{ puppet_server }}"
create: yes create: true
- name: Ensure default puppet exists - name: Ensure default puppet exists
copy: copy:
@ -70,11 +70,11 @@
dest: /etc/systemd/system/puppet.service dest: /etc/systemd/system/puppet.service
notify: Reload Systemd daemon notify: Reload Systemd daemon
#mkdir -p /etc/puppetlabs/code/environments/production/modules/ # mkdir -p /etc/puppetlabs/code/environments/production/modules/
#mkdir -p /etc/puppetlabs/code/environments/production/manifests/ # mkdir -p /etc/puppetlabs/code/environments/production/manifests/
- name: Ensure puppet agent service is enabled and running - name: Ensure puppet agent service is enabled and running
systemd: systemd:
name: puppet name: puppet
enabled: yes enabled: true
state: started state: started

View file

@ -2,12 +2,14 @@
- name: Ensure Puppet repository is installed - name: Ensure Puppet repository is installed
apt: apt:
deb: "https://apt.puppetlabs.com/puppet{{ puppet_version }}-release-{{ ansible_distribution_release }}.deb" deb: "https://apt.puppetlabs.com/puppet{{ puppet_version }}-release-{{ ansible_distribution_release }}.deb"
when: ansible_distribution_release != "hirsute" when:
- ansible_facts['distribution_release'] not in ['groovy', 'hirsute']
- name: Ensure Puppet repository is installed - name: Ensure Puppet repository is installed
apt: apt:
deb: "https://apt.puppetlabs.com/puppet{{ puppet_version }}-release-focal.deb" deb: "https://apt.puppetlabs.com/puppet{{ puppet_version }}-release-focal.deb"
when: ansible_distribution_release == "hirsute" when:
- ansible_facts['distribution_release'] in ['groovy', 'hirsute']
- name: Ensure puppet-agent is installed - name: Ensure puppet-agent is installed
package: package: