manage finding puppet command
This commit is contained in:
parent
d300c922ca
commit
4254d8675a
3 changed files with 56 additions and 36 deletions
|
@ -1,37 +1,55 @@
|
|||
---
|
||||
- name: Obtain path to puppet binary using which
|
||||
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
|
||||
- name: Check if puppet agent is present
|
||||
stat:
|
||||
path: "{{ which_puppet.stdout }}"
|
||||
register: which_puppet_stat
|
||||
path: /opt/puppetlabs/bin/puppet
|
||||
register: puppet_agent
|
||||
|
||||
- name: Set fact for puppet path
|
||||
set_fact:
|
||||
puppet_cmd: "{{ which_puppet.stdout }}"
|
||||
- name: Link agent to /usr/local/bin
|
||||
file:
|
||||
state: link
|
||||
dest: /usr/local/bin/puppet
|
||||
src: /opt/puppetlabs/bin/puppet
|
||||
when:
|
||||
- which_puppet.stdout != ""
|
||||
- which_puppet_stat.stat.executable
|
||||
- not which_puppet_stat.stat.isdir
|
||||
- puppet_agent.stat.exists
|
||||
|
||||
- name: Set fact for puppet path to estimated path when not found
|
||||
- name: Set puppet agent command
|
||||
set_fact:
|
||||
puppet_cmd: "/usr/local/bin/puppet"
|
||||
when: which_puppet.stdout == "" or not which_puppet_stat.stat.executable or which_puppet_stat.stat.isdir
|
||||
puppet_agent_cmd: /opt/puppetlabs/bin/puppet
|
||||
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
|
||||
shell: "{{ puppet_cmd }} config print confdir"
|
||||
shell: "{{ puppet_agent_cmd }} config print confdir"
|
||||
register: current_puppet_confdir
|
||||
|
||||
- name: Ensure puppet server is configured in main section
|
||||
|
@ -95,7 +113,7 @@
|
|||
mode: 0644
|
||||
|
||||
- name: Run puppet for the first time
|
||||
shell: "{{ puppet_cmd }} agent -t"
|
||||
shell: "{{ puppet_agent_cmd }} agent -t"
|
||||
when: run_puppet
|
||||
|
||||
- name: Ensure puppet agent service is enabled and started
|
||||
|
@ -109,6 +127,6 @@
|
|||
- name: Ensure puppet agent cron exists (WSL only)
|
||||
cron:
|
||||
name: puppet agent
|
||||
job: puppet agent -t
|
||||
job: "{{ puppet_agent_cmd }} agent -t"
|
||||
minute: '30'
|
||||
when: "'WSL' in ansible_facts['kernel']"
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
name:
|
||||
- ruby-full
|
||||
- ruby-augeas
|
||||
#- libaugeas0
|
||||
# - libaugeas0
|
||||
- libaugeas-dev
|
||||
#- augeas-tools
|
||||
# - augeas-tools
|
||||
|
||||
- name: Ensure Puppet agent gem is installed
|
||||
gem:
|
||||
|
@ -57,7 +57,7 @@
|
|||
section: main
|
||||
option: server
|
||||
value: "{{ puppet_server }}"
|
||||
create: yes
|
||||
create: true
|
||||
|
||||
- name: Ensure default puppet exists
|
||||
copy:
|
||||
|
@ -70,11 +70,11 @@
|
|||
dest: /etc/systemd/system/puppet.service
|
||||
notify: Reload Systemd daemon
|
||||
|
||||
#mkdir -p /etc/puppetlabs/code/environments/production/modules/
|
||||
#mkdir -p /etc/puppetlabs/code/environments/production/manifests/
|
||||
# mkdir -p /etc/puppetlabs/code/environments/production/modules/
|
||||
# mkdir -p /etc/puppetlabs/code/environments/production/manifests/
|
||||
|
||||
- name: Ensure puppet agent service is enabled and running
|
||||
systemd:
|
||||
name: puppet
|
||||
enabled: yes
|
||||
enabled: true
|
||||
state: started
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
- name: Ensure Puppet repository is installed
|
||||
apt:
|
||||
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
|
||||
apt:
|
||||
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
|
||||
package:
|
||||
|
|
Loading…
Reference in a new issue