fix finding puppet cmd
This commit is contained in:
parent
a8297c6f3a
commit
e32b76d7bf
1 changed files with 51 additions and 39 deletions
|
@ -1,73 +1,85 @@
|
||||||
---
|
---
|
||||||
|
- name: Initialize puppet agent command
|
||||||
|
set_fact:
|
||||||
|
puppet_agent_cmd: false
|
||||||
|
|
||||||
- name: Check if puppet agent is present
|
- name: Check if puppet agent is present
|
||||||
stat:
|
stat:
|
||||||
path: /opt/puppetlabs/bin/puppet
|
path: /opt/puppetlabs/bin/puppet
|
||||||
register: puppet_agent
|
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
|
- name: Set puppet agent command
|
||||||
set_fact:
|
set_fact:
|
||||||
puppet_agent_cmd: /opt/puppetlabs/bin/puppet
|
puppet_agent_cmd: /opt/puppetlabs/bin/puppet
|
||||||
when:
|
when:
|
||||||
- puppet_agent.stat.exists
|
- 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
|
- name: Find puppet agent
|
||||||
shell: which puppet
|
shell: which puppet
|
||||||
register: puppet_script
|
register: puppet_which
|
||||||
failed_when: puppet_script.rc == 127
|
failed_when: puppet_script.rc == 127
|
||||||
when:
|
when:
|
||||||
- not puppet_agent.stat.exists
|
- not puppet_agent_cmd
|
||||||
|
|
||||||
- name: Show puppet_script
|
- name: Show puppet_which
|
||||||
debug:
|
debug:
|
||||||
msg: "{{ puppet_script }}"
|
msg: "{{ puppet_which }}"
|
||||||
when:
|
when:
|
||||||
- not puppet_agent.stat.exists
|
- not puppet_agent_cmd
|
||||||
|
|
||||||
- name: Find puppet agent with whereis
|
- name: Get puppet command stats
|
||||||
shell: "whereis -b puppet | awk 'BEGIN {FS=\": \"} {print($2)}'"
|
stat:
|
||||||
register: puppet_script
|
path: puppet_which.stdout
|
||||||
failed_when: puppet_script.rc == 127
|
register: puppet_which_stat
|
||||||
when:
|
when:
|
||||||
- not puppet_agent.stat.exists
|
- not puppet_agent_cmd
|
||||||
- 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
|
|
||||||
|
|
||||||
- name: Set puppet agent command (from which)
|
- name: Set puppet agent command (from which)
|
||||||
set_fact:
|
set_fact:
|
||||||
puppet_agent_cmd: "{{ puppet_script.stdout }}"
|
puppet_agent_cmd: "{{ puppet_which.stdout }}"
|
||||||
when:
|
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
|
- name: Link agent to /usr/local/bin
|
||||||
file:
|
file:
|
||||||
state: link
|
state: link
|
||||||
dest: /usr/local/bin/puppet
|
dest: /usr/local/bin/puppet
|
||||||
src: "{{ puppet_agent_cmd }}"
|
src: "{{ puppet_agent_cmd }}"
|
||||||
when:
|
|
||||||
- puppet_agent_cmd != '/usr/local/bin/puppet'
|
|
||||||
|
|
||||||
|
|
||||||
- name: Obtain puppet configuration directory
|
- name: Obtain puppet configuration directory
|
||||||
shell: "/usr/local/bin/puppet config print confdir"
|
shell: "/usr/local/bin/puppet config print confdir"
|
||||||
|
|
Loading…
Reference in a new issue