--- - 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 - name: Find puppet agent shell: which puppet register: puppet_script failed_when: puppet_script.rc == 127 when: - not puppet_agent.stat.exists - name: Show puppet_script debug: msg: "{{ puppet_script }}" 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: 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) set_fact: puppet_agent_cmd: "{{ puppet_script.stdout }}" when: - not puppet_agent.stat.exists - 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" register: current_puppet_confdir - name: Ensure puppet server is configured in main section ini_file: path: "{{ current_puppet_confdir.stdout }}/puppet.conf" section: main option: server value: "{{ puppet_server }}" backup: yes create: yes mode: 0644 - name: Ensure puppet server is configured in master section ini_file: path: "{{ current_puppet_confdir.stdout }}/puppet.conf" section: master option: server value: "{{ puppet_server }}" backup: yes create: yes mode: 0644 - name: Ensure puppet port is configured in main section ini_file: path: "{{ current_puppet_confdir.stdout }}/puppet.conf" section: main option: serverport value: "{{ puppet_server_port }}" backup: yes create: yes mode: 0644 - name: Ensure puppet port is configured in master section ini_file: path: "{{ current_puppet_confdir.stdout }}/puppet.conf" section: master option: port value: "{{ puppet_server_port }}" backup: yes create: yes mode: 0644 - name: Ensure puppet run interval is configured in main section ini_file: path: "{{ current_puppet_confdir.stdout }}/puppet.conf" section: main option: runinterval value: "{{ puppet_runinterval }}" backup: yes create: yes mode: 0644 - name: Ensure puppet run interval is configured in master section ini_file: path: "{{ current_puppet_confdir.stdout }}/puppet.conf" section: master option: runinterval value: "{{ puppet_runinterval }}" backup: yes create: yes mode: 0644 - name: Run puppet for the first time shell: "/usr/local/bin/puppet agent -t" when: run_puppet - name: Ensure puppet agent service is enabled and started systemd: name: puppet enabled: true state: started masked: false when: "'WSL' not in ansible_facts['kernel']" - name: Ensure puppet agent cron exists (WSL only) cron: name: puppet agent job: "/usr/local/bin/puppet agent -t" minute: '30' when: "'WSL' in ansible_facts['kernel']"