WIP: posodobitve za novo verzijo Ansible #4
12 changed files with 25 additions and 18 deletions
|
|
@ -6,6 +6,7 @@ class FilterModule(object):
|
||||||
return {
|
return {
|
||||||
'defaultattr': self.defaultattr,
|
'defaultattr': self.defaultattr,
|
||||||
'list2dict': self.list2dict,
|
'list2dict': self.list2dict,
|
||||||
|
'any': self.any,
|
||||||
}
|
}
|
||||||
|
|
||||||
def defaultattr(self, objects, attr, val=None):
|
def defaultattr(self, objects, attr, val=None):
|
||||||
|
|
@ -19,3 +20,9 @@ class FilterModule(object):
|
||||||
Like items2dict but keep entire dictionaries as values.
|
Like items2dict but keep entire dictionaries as values.
|
||||||
'''
|
'''
|
||||||
return {item[key]: item for item in items}
|
return {item[key]: item for item in items}
|
||||||
|
|
||||||
|
def any(self, items):
|
||||||
|
'''
|
||||||
|
Return True if any item in the list is True.
|
||||||
|
'''
|
||||||
|
return any(items)
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,14 @@ iface {{ iface.name }}
|
||||||
{% for address in iface.ip_addresses %}
|
{% for address in iface.ip_addresses %}
|
||||||
address {{ address.address }}
|
address {{ address.address }}
|
||||||
{% if address.family.value == 4 %}
|
{% if address.family.value == 4 %}
|
||||||
{% set subnet = address.address | ipaddr('subnet') %}
|
{% set subnet = address.address | ansible.utils.ipaddr('subnet') %}
|
||||||
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
|
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
|
||||||
{% set gateway = prefix.custom_fields.gateway.address %}
|
{% set gateway = prefix.custom_fields.gateway.address %}
|
||||||
{% if gateway is defined and gateway != address.address %}
|
{% if gateway is defined and gateway != address.address %}
|
||||||
{% if iface.vrf %}
|
{% if iface.vrf %}
|
||||||
up ip route add default via {{ gateway | ipaddr('address') }} {% if iface.vrf.name %}vrf {{ iface.vrf.name }}{% endif +%}
|
up ip route add default via {{ gateway | ansible.utils.ipaddr('address') }} {% if iface.vrf.name %}vrf {{ iface.vrf.name }}{% endif +%}
|
||||||
{% else %}
|
{% else %}
|
||||||
gateway {{ gateway | ipaddr('address') }}
|
gateway {{ gateway | ansible.utils.ipaddr('address') }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
agents = [
|
agents = [
|
||||||
{% for address in query("netbox.netbox.nb_lookup", "devices", api_filter=snmp_hosts, raw_data=true)
|
{% for address in query("netbox.netbox.nb_lookup", "devices", api_filter=snmp_hosts, raw_data=true)
|
||||||
| selectattr("primary_ip4") | map(attribute="primary_ip4.address")
|
| selectattr("primary_ip4") | map(attribute="primary_ip4.address")
|
||||||
| ipaddr("int") | sort | ipaddr("address") %}
|
| ansible.utils.ipaddr("int") | sort | ansible.utils.ipaddr("address") %}
|
||||||
"{{ address }}",
|
"{{ address }}",
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@
|
||||||
when: not is_proxmox # proxmox has its own firewall configuration
|
when: not is_proxmox # proxmox has its own firewall configuration
|
||||||
|
|
||||||
- name: Run SSH instance in management VRF
|
- name: Run SSH instance in management VRF
|
||||||
when: interfaces | selectattr('vrf') | selectattr('vrf.name', '==', 'mgmt')
|
when: interfaces | selectattr('vrf') | selectattr('vrf.name', '==', 'mgmt') | any
|
||||||
block:
|
block:
|
||||||
- name: Configure SSH instance in management VRF
|
- name: Configure SSH instance in management VRF
|
||||||
copy:
|
copy:
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
{% for prefix in prefixes | selectattr('custom_fields.dhcp_server') | sort(attribute='vlan.name') %}
|
{% for prefix in prefixes | selectattr('custom_fields.dhcp_server') | sort(attribute='vlan.name') %}
|
||||||
{% if prefix.custom_fields.dhcp_server.address | ipaddr('address') == primary_ip4 %}
|
{% if prefix.custom_fields.dhcp_server.address | ansible.utils.ipaddr('address') == primary_ip4 %}
|
||||||
# {{ prefix.vlan.name }}
|
# {{ prefix.vlan.name }}
|
||||||
{% for range in prefix.custom_fields.dhcp_ranges | default([], true) %}
|
{% for range in prefix.custom_fields.dhcp_ranges | default([], true) %}
|
||||||
dhcp-range = set:{{ prefix.vlan.name }},{{ range.start_address | ipaddr('address') }},{{ range.end_address | ipaddr('address') }},{{ prefix.prefix | ipaddr('netmask') }}
|
dhcp-range = set:{{ prefix.vlan.name }},{{ range.start_address | ansible.utils.ipaddr('address') }},{{ range.end_address | ansible.utils.ipaddr('address') }},{{ prefix.prefix | ansible.utils.ipaddr('netmask') }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if prefix.custom_fields.gateway %}
|
{% if prefix.custom_fields.gateway %}
|
||||||
dhcp-option = tag:{{ prefix.vlan.name }},option:router,{{ prefix.custom_fields.gateway.address | ipaddr('address') }}
|
dhcp-option = tag:{{ prefix.vlan.name }},option:router,{{ prefix.custom_fields.gateway.address | ansible.utils.ipaddr('address') }}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
|
||||||
{% for host in hostvars.values() | selectattr('interfaces', 'defined') %}
|
{% for host in hostvars.values() | selectattr('interfaces', 'defined') %}
|
||||||
|
|
@ -24,5 +24,5 @@ dhcp-host = {{ interface.mac_address | lower }},{{ address }},{{ interface.devic
|
||||||
|
|
||||||
# custom reservations
|
# custom reservations
|
||||||
{% for reservation in reservations | default([]) %}
|
{% for reservation in reservations | default([]) %}
|
||||||
dhcp-host = {{ reservation.mac | lower }},{{ reservation.ip | ipaddr('address') }},{{ reservation.host | lower }}
|
dhcp-host = {{ reservation.mac | lower }},{{ reservation.ip | ansible.utils.ipaddr('address') }},{{ reservation.host | lower }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@
|
||||||
set_fact:
|
set_fact:
|
||||||
services: '{{
|
services: '{{
|
||||||
query("netbox.netbox.nb_lookup", "services", raw_data=true,
|
query("netbox.netbox.nb_lookup", "services", raw_data=true,
|
||||||
api_filter=("virtual_machine_id" if is_virtual else "device_id")+"="+id) }}'
|
api_filter=("virtual_machine_id" if is_virtual else "device_id")~"="~id) }}'
|
||||||
|
|
||||||
- when: 'cluster is defined and not is_virtual'
|
- when: 'cluster is defined and not is_virtual'
|
||||||
block:
|
block:
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,5 @@ ff02::2 ip6-allrouters
|
||||||
ff02::3 ip6-allhosts
|
ff02::3 ip6-allhosts
|
||||||
|
|
||||||
{% for address in interfaces | selectattr('name', '==', 'lo') | map(attribute='ip_addresses') | first %}
|
{% for address in interfaces | selectattr('name', '==', 'lo') | map(attribute='ip_addresses') | first %}
|
||||||
{{ address.address | ipaddr('address') }} {{ address.dns_name }} {{ inventory_hostname }}
|
{{ address.address | ansible.utils.ipaddr('address') }} {{ address.dns_name }} {{ inventory_hostname }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{% set lo = hostvars[inventory_hostname].interfaces | selectattr('name', '==', 'lo') | first %}
|
{% set lo = hostvars[inventory_hostname].interfaces | selectattr('name', '==', 'lo') | first %}
|
||||||
{% set vxlan_ip = lo.ip_addresses | selectattr('family.value', '==', 4)
|
{% set vxlan_ip = lo.ip_addresses | selectattr('family.value', '==', 4)
|
||||||
| map(attribute='address') | first
|
| map(attribute='address') | first
|
||||||
| ipaddr('address') %}
|
| ansible.utils.ipaddr('address') %}
|
||||||
iface lo
|
iface lo
|
||||||
# without this the local tunnel IP is sometimes advertised as 0.0.0.0 on boot
|
# without this the local tunnel IP is sometimes advertised as 0.0.0.0 on boot
|
||||||
vxlan-local-tunnelip {{ vxlan_ip }}
|
vxlan-local-tunnelip {{ vxlan_ip }}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
| selectattr('enabled') %}
|
| selectattr('enabled') %}
|
||||||
{% for address in iface.ip_addresses | selectattr("family.value", "==", 6) %}
|
{% for address in iface.ip_addresses | selectattr("family.value", "==", 6) %}
|
||||||
{# get the gateway for this subnet #}
|
{# get the gateway for this subnet #}
|
||||||
{% set subnet = address.address | ipaddr('subnet') %}
|
{% set subnet = address.address | ansible.utils.ipaddr('subnet') %}
|
||||||
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
|
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
|
||||||
{% set gateway = prefix.custom_fields.gateway.address %}
|
{% set gateway = prefix.custom_fields.gateway.address %}
|
||||||
{# if we are gateway, send RAs on this interface #}
|
{# if we are gateway, send RAs on this interface #}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
win_shell: >
|
win_shell: >
|
||||||
New-NetIPAddress -InterfaceAlias {{ interface.name }}
|
New-NetIPAddress -InterfaceAlias {{ interface.name }}
|
||||||
-AddressFamily IPv{{ address.family.value }}
|
-AddressFamily IPv{{ address.family.value }}
|
||||||
-IPAddress "{{ address.address | ipaddr("address") }}" -PrefixLength {{ address.address | ipaddr("prefix") }}
|
-IPAddress "{{ address.address | ansible.utils.ipaddr("address") }}" -PrefixLength {{ address.address | ansible.utils.ipaddr("prefix") }}
|
||||||
register: result
|
register: result
|
||||||
changed_when: "not result.stderr or 'Instance MSFT_NetIPAddress already exists' not in result.stderr"
|
changed_when: "not result.stderr or 'Instance MSFT_NetIPAddress already exists' not in result.stderr"
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
New-NetRoute -InterfaceAlias {{ interface.name }}
|
New-NetRoute -InterfaceAlias {{ interface.name }}
|
||||||
-AddressFamily IPv{{ address.family.value }}
|
-AddressFamily IPv{{ address.family.value }}
|
||||||
-DestinationPrefix {{ "0.0.0.0/0" if address.family.value == 4 else "::/0" }}
|
-DestinationPrefix {{ "0.0.0.0/0" if address.family.value == 4 else "::/0" }}
|
||||||
-NextHop {{ prefix.custom_fields.gateway.address | ipaddr("address") }}
|
-NextHop {{ prefix.custom_fields.gateway.address | ansible.utils.ipaddr("address") }}
|
||||||
register: result
|
register: result
|
||||||
changed_when: "not result.stderr or 'Instance MSFT_NetRoute already exists' not in result.stderr"
|
changed_when: "not result.stderr or 'Instance MSFT_NetRoute already exists' not in result.stderr"
|
||||||
failed_when: false
|
failed_when: false
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,11 @@ iface {{ iface.name }}{% if iface.name == 'lo' %} inet loopback{% endif +%}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for ip in iface.ip_addresses %}
|
{% for ip in iface.ip_addresses %}
|
||||||
address {{ ip.address }}
|
address {{ ip.address }}
|
||||||
{% set subnet = ip.address | ipaddr('subnet') %}
|
{% set subnet = ip.address | ansible.utils.ipaddr('subnet') %}
|
||||||
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
|
{% set prefix = prefixes | selectattr('prefix', '==', subnet) | first %}
|
||||||
{% set gateway = prefix.custom_fields.gateway.address %}
|
{% set gateway = prefix.custom_fields.gateway.address %}
|
||||||
{% if gateway is defined %}
|
{% if gateway is defined %}
|
||||||
gateway {{ gateway | ipaddr('address') }}
|
gateway {{ gateway | ansible.utils.ipaddr('address') }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,5 +11,5 @@ ff02::3 ip6-allhosts
|
||||||
| map(attribute='interfaces') | flatten
|
| map(attribute='interfaces') | flatten
|
||||||
| map(attribute='ip_addresses') | flatten
|
| map(attribute='ip_addresses') | flatten
|
||||||
| selectattr('dns_name') %}
|
| selectattr('dns_name') %}
|
||||||
{{ address.address | ipaddr('address') }} {{ address.dns_name }} {{ address.dns_name | split('.') | first }}
|
{{ address.address | ansible.utils.ipaddr('address') }} {{ address.dns_name }} {{ address.dns_name | split('.') | first }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue