fix finding puppet cmd

This commit is contained in:
Antonio J. Delgado 2022-10-24 12:55:55 +03:00
parent a8297c6f3a
commit e32b76d7bf

View file

@ -1,73 +1,85 @@
---
- 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: Link agent to /usr/local/bin
file:
state: link
dest: /usr/local/bin/puppet
src: /opt/puppetlabs/bin/puppet
when:
- puppet_agent.stat.exists
- 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
shell: which puppet
register: puppet_script
register: puppet_which
failed_when: puppet_script.rc == 127
when:
- not puppet_agent.stat.exists
- not puppet_agent_cmd
- name: Show puppet_script
- name: Show puppet_which
debug:
msg: "{{ puppet_script }}"
msg: "{{ puppet_which }}"
when:
- not puppet_agent.stat.exists
- not puppet_agent_cmd
- name: Find puppet agent with whereis
shell: "whereis -b puppet | awk 'BEGIN {FS=\": \"} {print($2)}'"
register: puppet_script
failed_when: puppet_script.rc == 127
- name: Get puppet command stats
stat:
path: puppet_which.stdout
register: puppet_which_stat
when:
- not puppet_agent.stat.exists
- puppet_script.stdout == ''
- name: Show puppet_script
debug:
msg: "{{ puppet_script }}"
when:
- not puppet_agent.stat.exists
- 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
- not puppet_agent_cmd
- name: Set puppet agent command (from which)
set_fact:
puppet_agent_cmd: "{{ puppet_script.stdout }}"
puppet_agent_cmd: "{{ puppet_which.stdout }}"
when:
- not puppet_agent.stat.exists
- 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
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 which)
set_fact:
puppet_agent_cmd: "{{ puppet_whereis.stdout }}"
when:
- 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"