---
- name: 'Verify Ansible versions'
  hosts: all
  tags: always
  become: false
  run_once: true
  gather_facts: false
  tasks:
    - local_action: command ./roles.py --check
      changed_when: false

- name: Configure network mainnet bootnodes
  become: true
  serial: '{{ serial|default(1) }}'
  hosts: 'nimbus-mainnet-small'
  vars_files: layout/mainnet.yml
  vars:
    # WARNING: Since these are Eth 2 bootnodes we need to keep the keys and IPs unchanged.
    beacon_node_netkey: '{{lookup("bitwarden", "nimbus/netkey", field=hostname)}}'
  roles:
    - { role: infra-role-swap-file,         tags: [ swap-file ] }
    - { role: redirect-ports,               tags: [ redirect-ports ] }
    - { role: get-geth-api-urls,            tags: [ get-geth-api-urls, beacon-node ] }
  tasks:
    - include_role:
        name: infra-role-beacon-node-linux
        apply: { tags: always }
      tags: [ beacon-node ]
      with_items: '{{ nodes_layout[inventory_hostname] }}'
      loop_control:
        loop_var: node
        index_var: idx

- name: Deploy mainnet linux beacon nodes
  become: true
  serial: '{{ serial|default(1) }}'
  hosts: nimbus-mainnet-metal
  vars_files: layout/mainnet.yml
  vars:
    # FIXME: Use all Geth nodes available in the fleet until we resync.
    geth_node_api_fleet_names: ['nimbus.geth']
  roles:
    - { role: update-netplan,               tags: [ update-netplan ], when: ansible_system == 'Linux' }
    - { role: infra-role-swap-file,         tags: [ swap-file ] }
    - { role: infra-role-open-ports,        tags: [ open-ports ] }
    - { role: infra-role-smart-metrics,     tags: [ smart-metrics ] }
    - { role: redirect-ports,               tags: [ redirect-ports ] }
    - { role: infra-role-geth,              tags: [ infra-role-geth ] }
    - { role: infra-role-geth-exporter,     tags: [ infra-role-geth-exporter ] }
    - { role: get-geth-api-urls,            tags: [ get-geth-api-urls, beacon-node ] }
    - { role: nimbus-era-files,             tags: [ nimbus-era-files ] }
  tasks:
    - include_role:
        name: infra-role-beacon-node-linux
        apply: { tags: always }
      tags: [ beacon-node ]
      with_items: '{{ nodes_layout[inventory_hostname] }}'
      loop_control:
        loop_var: node
        index_var: idx