summaryrefslogtreecommitdiff
path: root/roles/vyos_common/tasks/main.yml
blob: b1dc29cd329e6aa33d17d33e05b9f416edf14640 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
- name: Set hostname
  vyos.vyos.vyos_hostname:
    config:
      hostname: "{{ vm_name }}"
    state: merged

# Build the vyos_interfaces config list from Netbox's interface data, one
# entry per interface, without needing a template file for something this
# structurally simple.
- name: Build interface enable/description config from Netbox data
  ansible.builtin.set_fact:
    vyos_interfaces_config: "{{ vyos_interfaces_config | default([]) + [{
        'name': item.name,
        'enabled': true,
        'description': item.description | default(item.name)
      }] }}"
  loop: "{{ vm_interfaces }}"
  loop_control:
    label: "{{ item.name }}"

- name: Apply interface enable/description state
  vyos.vyos.vyos_interfaces:
    config: "{{ vyos_interfaces_config }}"
    state: merged

# Same pattern for L3 addressing — only interfaces that actually have an
# IP assigned in Netbox get an ipv4 block; DHCP-addressed interfaces (no
# Netbox IP) are skipped here and left for the appliance-specific role.
- name: Build L3 addressing config from Netbox data
  ansible.builtin.set_fact:
    vyos_l3_interfaces_config: "{{ vyos_l3_interfaces_config | default([]) + [{
        'name': item.name,
        'ipv4': item.ip_addresses | map(attribute='address') | map('community.general.dict_kv', 'address') | list
      }] }}"
  loop: "{{ vm_interfaces }}"
  loop_control:
    label: "{{ item.name }}"
  when: item.ip_addresses | default([]) | length > 0

- name: Apply L3 addressing
  vyos.vyos.vyos_l3_interfaces:
    config: "{{ vyos_l3_interfaces_config | default([]) }}"
    state: merged
  when: vyos_l3_interfaces_config is defined

- name: Configure NTP servers
  vyos.vyos.vyos_ntp_global:
    config:
      servers: "{{ vyos_ntp_servers | map('community.general.dict_kv', 'address') | list }}"
    state: merged
  when: vyos_ntp_servers | length > 0

- name: Configure remote syslog
  vyos.vyos.vyos_logging_global:
    config:
      hosts:
        - hostname: "{{ vyos_syslog_host }}"
    state: merged
  when: vyos_syslog_host | length > 0