---
- name: Create puppet config directory
  file:
    path: /etc/puppetlabs/puppet/
    state: directory

- name: remove current config
  ansible.builtin.file:
    path: /etc/puppetlabs/puppet/puppet.conf
    state: absent

- name: generate new config
  ansible.builtin.template:
    src: puppet.conf.j2
    dest: /etc/puppetlabs/puppet/puppet.conf

#- name: make sure puppet agent stopped
#  ansible.builtin.service:
#    name: puppet
#    state: stopped
#
#- name: make cert request
#  ansible.builtin.shell:
#    cmd: /opt/puppetlabs/bin/puppet agent -t --waitforcert 300

- name: start puppet agent
  ansible.builtin.service:
    name: puppet
    state: started