Replace usage of networkd template with role
For consistency reasons instead of placing a template for systemd-networkd we better use systemd_networkd role that is present for a while. Change-Id: I1e9deaa2892a8fa7eb171acaf75441d7efeac297
This commit is contained in:
parent
0b7a8645de
commit
517b75ac61
@ -57,22 +57,6 @@
|
|||||||
changed_when: false
|
changed_when: false
|
||||||
listen: Lxc container restart
|
listen: Lxc container restart
|
||||||
|
|
||||||
- name: Flush addresses
|
|
||||||
command: "ip addr flush {{ item.value.interface }}"
|
|
||||||
with_dict: "{{ lxc_container_networks_combined }}"
|
|
||||||
failed_when: false
|
|
||||||
when:
|
|
||||||
- item.value.interface is defined
|
|
||||||
listen: Restart networkd
|
|
||||||
|
|
||||||
- name: Restart systemd-networkd
|
|
||||||
systemd:
|
|
||||||
name: systemd-networkd
|
|
||||||
state: restarted
|
|
||||||
enabled: true
|
|
||||||
daemon_reload: true
|
|
||||||
listen: Restart networkd
|
|
||||||
|
|
||||||
- name: Enable resolved
|
- name: Enable resolved
|
||||||
systemd:
|
systemd:
|
||||||
name: systemd-resolved
|
name: systemd-resolved
|
||||||
|
@ -210,7 +210,7 @@
|
|||||||
changed_when: wiring_script.rc == 3
|
changed_when: wiring_script.rc == 3
|
||||||
delegate_to: "{{ physical_host }}"
|
delegate_to: "{{ physical_host }}"
|
||||||
|
|
||||||
- include_tasks: "lxc_container_network_new.yml"
|
- include_tasks: "lxc_container_network.yml"
|
||||||
# VETH AND CONNECTIVITY SETTINGS
|
# VETH AND CONNECTIVITY SETTINGS
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,23 +13,14 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
- name: Create networkd directory
|
|
||||||
file:
|
|
||||||
path: "/etc/systemd/network"
|
|
||||||
state: directory
|
|
||||||
|
|
||||||
- name: Drop container network file (interfaces)
|
- name: Run the systemd-networkd role
|
||||||
template:
|
import_role:
|
||||||
src: "container_network.network.j2"
|
name: systemd_networkd
|
||||||
dest: "/etc/systemd/network/{{ item.value.interface }}.network"
|
vars:
|
||||||
owner: "root"
|
systemd_run_networkd: true
|
||||||
group: "root"
|
systemd_networkd_distro_packages: []
|
||||||
mode: "0644"
|
systemd_networks: "{{ _lxc_container_systemd_networks }}"
|
||||||
with_dict: "{{ lxc_container_networks_combined }}"
|
|
||||||
notify:
|
|
||||||
- Enable dbus
|
|
||||||
- Enable resolved
|
|
||||||
- Restart networkd
|
|
||||||
|
|
||||||
- name: Create resolved link
|
- name: Create resolved link
|
||||||
file:
|
file:
|
@ -1,46 +0,0 @@
|
|||||||
[Match]
|
|
||||||
Name={{ item.value.interface }}
|
|
||||||
|
|
||||||
{% if item.value.address is defined %}
|
|
||||||
[Address]
|
|
||||||
{% set addr_cidr = (item.value.address | string + '/' + item.value.netmask | string) | ansible.utils.ipaddr('prefix') %}
|
|
||||||
Address={{ item.value.address }}/{{ addr_cidr }}
|
|
||||||
{% else %}
|
|
||||||
[DHCP]
|
|
||||||
{% if item.value.dhcp_use_dns is defined %}
|
|
||||||
UseDNS={{ item.value.dhcp_use_dns | bool | lower }}
|
|
||||||
{% else %}
|
|
||||||
UseDNS={{ (lxc_container_enable_resolved | bool) | ternary('yes', 'no') }}
|
|
||||||
{% endif %}
|
|
||||||
UseNTP=yes
|
|
||||||
RouteMetric=20
|
|
||||||
{% if hostvars[inventory_hostname]['gateway'] is defined
|
|
||||||
or item.value.dhcp_use_routes is defined %}
|
|
||||||
UseRoutes={{ item.value.dhcp_use_routes | default(false) | bool | lower }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% for route in item.value.static_routes | default([]) %}
|
|
||||||
[Route]
|
|
||||||
Destination={{ route['cidr'] }}
|
|
||||||
Gateway={{ route['gateway'] }}
|
|
||||||
Metric={{ 20 + loop.index }}
|
|
||||||
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
[Network]
|
|
||||||
{% if item.value.address is defined %}
|
|
||||||
{% set addr_cidr = (item.value.address | string + '/' + item.value.netmask | string) | ansible.utils.ipaddr('prefix') %}
|
|
||||||
Address={{ item.value.address }}/{{ addr_cidr }}
|
|
||||||
{% else %}
|
|
||||||
DHCP=yes
|
|
||||||
{% endif %}
|
|
||||||
{% if item.value.gateway is defined %}
|
|
||||||
Gateway={{ item.value.gateway }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
[Link]
|
|
||||||
{% if item.value.mtu is defined %}
|
|
||||||
MTUBytes={{ item.value.mtu }}
|
|
||||||
{% endif %}
|
|
@ -33,3 +33,20 @@ lxc_container_default_config_list:
|
|||||||
lxc_container_networks_combined: "{{ container_networks | default({}) | combine(container_extra_networks | default({})) | combine(lxc_container_networks) }}"
|
lxc_container_networks_combined: "{{ container_networks | default({}) | combine(container_extra_networks | default({})) | combine(lxc_container_networks) }}"
|
||||||
sysctl_path: "/sbin"
|
sysctl_path: "/sbin"
|
||||||
_lxc_container_bind_mounts: []
|
_lxc_container_bind_mounts: []
|
||||||
|
|
||||||
|
_lxc_container_systemd_networks: |
|
||||||
|
{% set systemd_networks = [] %}
|
||||||
|
{% for network in lxc_container_networks_combined.values() %}
|
||||||
|
{% set _ = systemd_networks.append({
|
||||||
|
'filename': network.interface,
|
||||||
|
'interface': network.interface,
|
||||||
|
'address': network.address | default('dhcp'),
|
||||||
|
'netmask': network.netmask | default(),
|
||||||
|
'gateway': network.gateway | default(),
|
||||||
|
'mtu': network.mtu | default(),
|
||||||
|
'static_routes': network.static_routes | default([]),
|
||||||
|
'usedns': ('dhcp_use_dns' in network) | ternary(network.dhcp_use_dns, lxc_container_enable_resolved | bool),
|
||||||
|
'config_overrides': ('dhcp_use_routes' in network) | ternary({'DHCP': network.dhcp_use_routes}, {})
|
||||||
|
}) %}
|
||||||
|
{% endfor %}
|
||||||
|
{{ systemd_networks }}
|
||||||
|
Loading…
Reference in New Issue
Block a user