- hosts: all
  tasks:
    - name: Create nodepool directory
      file:
        path: /etc/nodepool
        state: directory
    - name: Create nodepool subnodes file
      copy:
        dest: /etc/nodepool/sub_nodes_private
        content: ""
    - name: Populate nodepool subnodes file
      lineinfile:
        path: /etc/nodepool/sub_nodes_private
        line: "{{ hostvars[item]['nodepool']['private_ipv4'] }}"
      with_items: "{{ groups['subnodes'] }}"
      when: groups['subnodes'] is defined
    - name: Create nodepool primary file
      copy:
        dest: /etc/nodepool/primary_node_private
        content: "{{ hostvars['primary']['nodepool']['private_ipv4'] }}"
      when: hostvars['primary'] is defined
    - name: Copy ssh keys to nodepool directory
      command: "cp .ssh/{{ item }} /etc/nodepool/{{ item }}"
      with_items:
        - id_rsa
        - id_rsa.pub