---
# This playbook should be run from the master node
- hosts: all
  vars:
    node_ip_address: 10.254.0.254

- hosts: node_ip_address
  tasks:
  - name: Create ssh directory
    file:
      path: /root/.ssh
      state: directory
      mode: '0700'
  - name: Add master node key to node
    blockinfile:
      block: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
      dest: /root/.ssh/authorized_keys
      create: yes

- hosts: masters
  tasks:
  - name: Add node to master cockpit
    template:
      src: cockpit-machine.j2
      dest: /etc/cockpit/machines.d/{{node_ip_address}}-sotolito.json
      owner: root
      group: wheel
      mode: '0644'


---
# This playbook should be run from the master node
- hosts: node_ip_address
  vars:
    node_ip_address: 10.254.0.254
 tasks:
  - name: Create ssh directory
    file:
      path: /root/.ssh
      state: directory
      mode: '0700'
  - name: Add master node key to node
    blockinfile:
      block: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
      dest: /root/.ssh/authorized_keys
      create: yes

- hosts: masters
  tasks:
  - name: Add node to master cockpit
    template:
      src: cockpit-machine.j2
      dest: /etc/cockpit/machines.d/{{node_ip_address}}-sotolito.json
      owner: root
      group: wheel
      mode: '0644'


Fix variables on add node playbook
Fix variables on add node playbook
