From 4254d8675a989e2e6421fa5072d7580e1a89bd17 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Mon, 24 Oct 2022 12:18:13 +0300 Subject: [PATCH] manage finding puppet command --- tasks/configure.yml | 74 +++++++++++++++++++++++++--------------- tasks/install_arm.yml | 12 +++---- tasks/install_x86_64.yml | 6 ++-- 3 files changed, 56 insertions(+), 36 deletions(-) diff --git a/tasks/configure.yml b/tasks/configure.yml index 5c24b80..a61780f 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -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']" diff --git a/tasks/install_arm.yml b/tasks/install_arm.yml index ecdc389..d9c354f 100644 --- a/tasks/install_arm.yml +++ b/tasks/install_arm.yml @@ -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 diff --git a/tasks/install_x86_64.yml b/tasks/install_x86_64.yml index dc359e4..f424f87 100644 --- a/tasks/install_x86_64.yml +++ b/tasks/install_x86_64.yml @@ -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: