50 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			YAML
		
	
	
	
	
	
---
 | 
						|
- name: Configure NetworkManager [ type loopback ]
 | 
						|
  community.general.nmcli:
 | 
						|
    autoconnect: "{{ connection.autoconnect | default('true') }}"
 | 
						|
    conn_name: "{{ connection.con_name | default('lo') }}"
 | 
						|
    ifname: "{{ connection.ifname | default('lo') }}"
 | 
						|
    type: "{{ connection.type }}"
 | 
						|
    ip4: "{{ connection.ip4 | default('') }}"
 | 
						|
    dns4: "{{ connection.dns4 | default([]) }}"
 | 
						|
    method4: "{{ connection.method4 | default('manual') }}"
 | 
						|
    method6: "{{ connection.method6 | default('auto') }}"
 | 
						|
    state: present
 | 
						|
  with_items: "{{ network }}"
 | 
						|
  when: connection.type == 'loopback'
 | 
						|
  loop_control:
 | 
						|
    loop_var: connection
 | 
						|
  notify: Restart NetworkManager
 | 
						|
 | 
						|
- name: Configure NetworkManager [ type ethernet ]
 | 
						|
  community.general.nmcli:
 | 
						|
    "{{ connection_params | combine(dynamic_params) }}"
 | 
						|
  with_items: "{{ network }}"
 | 
						|
  when: connection.type == 'ethernet'
 | 
						|
  loop_control:
 | 
						|
    loop_var: connection
 | 
						|
  vars:
 | 
						|
    connection_params:
 | 
						|
      autoconnect: "{{ connection.autoconnect | default('true') }}"
 | 
						|
      conn_name: "{{ connection.con_name }}"
 | 
						|
      ifname: "{{ connection.ifname | default(connection.con_name) }}"
 | 
						|
      type: "{{ connection.type }}"
 | 
						|
      state: "{{ connection.state | default('present') }}"
 | 
						|
    dynamic_params: >-
 | 
						|
      {{
 | 
						|
        dict(
 | 
						|
          ip4=connection.ip4 if connection.ip4 is defined else omit,
 | 
						|
          gw4=connection.gw4 if connection.gw4 is defined else omit,
 | 
						|
          dns4=connection.dns4 if connection.dns4 is defined else omit,
 | 
						|
          routes4=connection.routes4 if connection.routes4 is defined else omit,
 | 
						|
          method4=connection.method4 if connection.method4 is defined else 'disabled',
 | 
						|
          ip6=connection.ip6 if connection.ip6 is defined else omit,
 | 
						|
          gw6=connection.gw6 if connection.gw6 is defined else omit,
 | 
						|
          method6=connection.method6 if connection.method6 is defined else 'disabled'
 | 
						|
        )
 | 
						|
      }}
 | 
						|
  notify: Restart NetworkManager
 | 
						|
 | 
						|
#  notify: 
 | 
						|
#    - networking changed
 | 
						|
#    - network-manager configuration changed |