---
# 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'


---
# This playbook should be run from the master node
- hosts: "{{node_ip_address}}"
  vars:
    node_ip_address: 10.254.0.254
    node_name: sotolito-node{{node_ip_address.split(".")[3]}}
  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
  - name: "Set hostname {{ node_hostname }}"
    command: "hostnamectl set-hostname {{ node_name }}"

- hosts: masters
  vars:
    node_name: sotolito-node{{node_ip_address.split(".")[3]}}
  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'


Add hostname change to node playbook
Add hostname change to node playbook
