Refactor network role
This commit is contained in:
parent
71d1da1cf1
commit
e7602bd910
@ -1 +1,28 @@
|
||||
---
|
||||
# network_netplan_version: 2
|
||||
# network_netplan_renderer: networkd
|
||||
network_netplan_etc_path: /etc/netplan
|
||||
network_netplan_config_path: "{{ network_netplan_etc_path }}/ansible.yaml"
|
||||
network_netplan_default_config_path: "{{ network_netplan_etc_path }}/01-netcfg.yaml"
|
||||
# network_netplan_default_config_state: absent
|
||||
|
||||
network_interfaces:
|
||||
- name: eth0
|
||||
inet4:
|
||||
dhcp: false
|
||||
address:
|
||||
- "{{ ansible_default_ipv4.address }}/{{ (ansible_default_ipv4.network + '/' + ansible_default_ipv4.netmask) | ansible.utils.ipaddr('prefix') }}"
|
||||
gateway: "{{ ansible_default_ipv4.gateway }}"
|
||||
inet6:
|
||||
dhcp: false
|
||||
address:
|
||||
- "{{ ansible_default_ipv6.address }}/{{ ansible_default_ipv6.prefix }}"
|
||||
gateway: "{{ ansible_default_ipv6.gateway }}"
|
||||
|
||||
network_dns_nameservers:
|
||||
- 8.8.8.8
|
||||
- 1.1.1.1
|
||||
- 9.9.9.9
|
||||
- 8.8.4.4
|
||||
- 1.0.0.1
|
||||
- 149.112.112.112
|
||||
|
@ -1,60 +0,0 @@
|
||||
galaxy_info:
|
||||
author: your name
|
||||
description: your description
|
||||
company: your company (optional)
|
||||
|
||||
# If the issue tracker for your role is not on github, uncomment the
|
||||
# next line and provide a value
|
||||
# issue_tracker_url: http://example.com/issue/tracker
|
||||
|
||||
# Some suggested licenses:
|
||||
# - BSD (default)
|
||||
# - MIT
|
||||
# - GPLv2
|
||||
# - GPLv3
|
||||
# - Apache
|
||||
# - CC-BY
|
||||
license: license (GPLv2, CC-BY, etc)
|
||||
|
||||
min_ansible_version: 2.4
|
||||
|
||||
# If this a Container Enabled role, provide the minimum Ansible Container version.
|
||||
# min_ansible_container_version:
|
||||
|
||||
# Optionally specify the branch Galaxy will use when accessing the GitHub
|
||||
# repo for this role. During role install, if no tags are available,
|
||||
# Galaxy will use this branch. During import Galaxy will access files on
|
||||
# this branch. If Travis integration is configured, only notifications for this
|
||||
# branch will be accepted. Otherwise, in all cases, the repo's default branch
|
||||
# (usually master) will be used.
|
||||
#github_branch:
|
||||
|
||||
#
|
||||
# Provide a list of supported platforms, and for each platform a list of versions.
|
||||
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
|
||||
# To view available platforms and versions (or releases), visit:
|
||||
# https://galaxy.ansible.com/api/v1/platforms/
|
||||
#
|
||||
# platforms:
|
||||
# - name: Fedora
|
||||
# versions:
|
||||
# - all
|
||||
# - 25
|
||||
# - name: SomePlatform
|
||||
# versions:
|
||||
# - all
|
||||
# - 1.0
|
||||
# - 7
|
||||
# - 99.99
|
||||
|
||||
galaxy_tags: []
|
||||
# List tags for your role here, one per line. A tag is a keyword that describes
|
||||
# and categorizes the role. Users find roles by searching for tags. Be sure to
|
||||
# remove the '[]' above, if you add tags to this list.
|
||||
#
|
||||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
||||
# Maximum 20 tags per role.
|
||||
|
||||
dependencies: []
|
||||
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||
# if you add dependencies to this list.
|
@ -1,6 +1,3 @@
|
||||
---
|
||||
- name: Include netplan vars
|
||||
include_vars: netplan.yaml
|
||||
|
||||
- name: Include netplan tasks
|
||||
include_tasks: netplan.yml
|
||||
ansible.builtin.include_tasks: netplan.yml
|
||||
|
@ -1,9 +1,18 @@
|
||||
---
|
||||
- name: Remove default netplan configuration
|
||||
ansible.builtin.file:
|
||||
path: "{{ network_netplan_default_config_path }}"
|
||||
state: "{{ network_netplan_default_config_state | default('absent') }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: 0644
|
||||
notify: netplan apply
|
||||
|
||||
- name: Configure netplan
|
||||
copy:
|
||||
dest: /etc/netplan/01-netcfg.yaml
|
||||
ansible.builtin.template:
|
||||
dest: "{{ network_netplan_config_path }}"
|
||||
src: netplan.yaml.j2
|
||||
owner: root
|
||||
group: root
|
||||
mode: '0644'
|
||||
content: "{{ network_netplan_config | to_nice_yaml }}"
|
||||
notify: netplan apply
|
||||
|
38
roles/network/templates/netplan.yaml.j2
Normal file
38
roles/network/templates/netplan.yaml.j2
Normal file
@ -0,0 +1,38 @@
|
||||
---
|
||||
network:
|
||||
version: "{{ network_netplan_version | default(2) }}"
|
||||
renderer: "{{ network_netplan_renderer | default("networkd") }}"
|
||||
{% if network_interfaces is defined and network_interfaces | length %}
|
||||
ethernets:
|
||||
{% for iface in network_interfaces %}
|
||||
{{ iface['name'] }}:
|
||||
{% if iface['inet4']['dhcp'] is defined %}
|
||||
dhcp4: "{{ iface['inet4']['dhcp'] | ternary('yes', 'no') }}"
|
||||
{% endif %}
|
||||
{% if iface['inet4']['dhcp'] is defined %}
|
||||
dhcp6: "{{ iface['inet6']['dhcp'] | ternary('yes', 'no') }}"
|
||||
{% endif %}
|
||||
{% if iface['inet4']['address'] is defined or iface['inet6']['address'] is defined %}
|
||||
addresses:
|
||||
{% for ip in iface['inet4']['address'] | default([]) %}
|
||||
- {{ ip }}
|
||||
{% endfor %}
|
||||
{% for ip in iface['inet6']['address'] | default([]) %}
|
||||
- {{ ip }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if iface['inet4']['gateway'] is defined %}
|
||||
gateway4: "{{ iface['inet4']['gateway'] }}"
|
||||
{% endif %}
|
||||
{% if iface['inet6']['gateway'] is defined %}
|
||||
gateway6: "{{ iface['inet6']['gateway'] }}"
|
||||
{% endif %}
|
||||
{% if network_dns_nameservers is defined %}
|
||||
nameservers:
|
||||
addresses:
|
||||
{% for ip in network_dns_nameservers %}
|
||||
- {{ ip }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
@ -1,15 +0,0 @@
|
||||
network_netplan_config:
|
||||
network:
|
||||
version: 2
|
||||
renderer: networkd
|
||||
ethernets:
|
||||
eth0:
|
||||
dhcp4: 'no'
|
||||
dhcp6: 'no'
|
||||
addresses:
|
||||
- "{{ ansible_default_ipv4.address }}/{{ (ansible_default_ipv4.network + '/' + ansible_default_ipv4.netmask) | ansible.utils.ipaddr('prefix') }}"
|
||||
- "{{ ansible_default_ipv6.address }}/{{ ansible_default_ipv6.prefix }}"
|
||||
gateway4: "{{ ansible_default_ipv4.gateway }}"
|
||||
gateway6: "{{ ansible_default_ipv6.gateway }}"
|
||||
nameservers:
|
||||
addresses: "{{ dns_servers }}"
|
Loading…
Reference in New Issue
Block a user