---
- name: install bird packages
  package:
    name: "{{ item }}"
    state: present
  loop:
    - bird-bgp
    - bird-doc

- name: set directory permissions for /etc/bird
  file:
    path: /etc/bird
    state: directory
    mode: 0755

- name: write bird.conf
  template:
    src: bird.conf.j2
    dest: /etc/bird/bird.conf
    mode: 0640
    owner: bird
    group: bird
  notify: reload systemd unit bird

- name: write bird6.conf
  template:
    src: bird6.conf.j2
    dest: /etc/bird/bird6.conf
    mode: 0640
    owner: bird
    group: bird
  notify: reload systemd unit bird6

- name: write mwu_ipv4_peers.conf
  template:
    src: mwu_ipv4_peers.conf.j2
    dest: /etc/bird/mwu_ipv4_peers.conf
    mode: 0640
    owner: bird
    group: bird
  tags: sync-peers
  notify: reload systemd unit bird

- name: write mwu_ipv6_peers.conf
  template:
    src: mwu_ipv6_peers.conf.j2
    dest: /etc/bird/mwu_ipv6_peers.conf
    mode: 0640
    owner: bird
    group: bird
  tags: sync-peers
  notify: reload systemd unit bird6

- name: write radv.conf
  when: server_type == "gateway"
  template:
    src: radv.conf.j2
    dest: /etc/bird/radv.conf
    mode: 0640
    owner: bird
    group: bird
  notify: reload systemd unit bird6

- name: enable + start systemd units bird + bird6
  systemd:
    name: bird{{ item }}
    enabled: yes
    state: started
  loop:
    - ""
    - 6