mirror of
				https://github.com/iiab/iiab.git
				synced 2025-03-09 15:40:17 +00:00 
			
		
		
		
	split out netplan2
This commit is contained in:
		
							parent
							
								
									93694e853b
								
							
						
					
					
						commit
						343d00848f
					
				
					 3 changed files with 107 additions and 23 deletions
				
			
		
							
								
								
									
										66
									
								
								roles/network/tasks/netplan.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								roles/network/tasks/netplan.yml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,66 @@
 | 
			
		|||
# netplan.yml
 | 
			
		||||
- name: Figure out netplan file name on Ubuntu 18
 | 
			
		||||
  shell: ls /etc/netplan
 | 
			
		||||
  register: netplan
 | 
			
		||||
 | 
			
		||||
- name: Remove stock netplan template
 | 
			
		||||
  file:
 | 
			
		||||
    state: absent
 | 
			
		||||
    dest: /etc/netplan/{{ netplan }}
 | 
			
		||||
 | 
			
		||||
# Was needed at one point retesting current needs
 | 
			
		||||
#- name: Disable and mask systemd-networkd-wait-online
 | 
			
		||||
#  systemd:
 | 
			
		||||
#    name: systemd-networkd-wait-online
 | 
			
		||||
#    enabled: no
 | 
			
		||||
#    masked: yes
 | 
			
		||||
#    state: stopped
 | 
			
		||||
 | 
			
		||||
- name: Disable and mask cloud-init
 | 
			
		||||
  systemd:
 | 
			
		||||
    name: "{{ item }}"
 | 
			
		||||
    enabled: no
 | 
			
		||||
    masked: yes
 | 
			
		||||
    state: stopped
 | 
			
		||||
  with_items:
 | 
			
		||||
   - cloud-init-local
 | 
			
		||||
   - cloud-init
 | 
			
		||||
  when: "{{ netplan }}" == "50-cloud-init.yaml"
 | 
			
		||||
 | 
			
		||||
# ICO will always set gui_static_wan_ip away from the default of 'unset' while
 | 
			
		||||
# gui_static_wan turns dhcp on/off through wan_ip in computed_network and
 | 
			
		||||
# overrides gui_static_wan_ip that is present. Changing wan_ip in local_vars
 | 
			
		||||
# is a oneway street to static.
 | 
			
		||||
 | 
			
		||||
- name: Static IP computing CIDR
 | 
			
		||||
  shell: netmask {{ wan_ip }}/{{ wan_netmask }} | awk -F "/" '{print $2}'
 | 
			
		||||
  register: CIDR
 | 
			
		||||
  when: wan_ip != "dhcp"
 | 
			
		||||
 | 
			
		||||
- name: Static IP setting CIDR
 | 
			
		||||
  set_fact:
 | 
			
		||||
    wan_cidr: "{{ CIDR.stdout }}"
 | 
			
		||||
  when: wan_ip != "dhcp"
 | 
			
		||||
 | 
			
		||||
- name: Supply netplan template
 | 
			
		||||
  template:
 | 
			
		||||
    dest:  /etc/netplan/01-iiab-config
 | 
			
		||||
    src: network/netplan.j2
 | 
			
		||||
    backup: no
 | 
			
		||||
 | 
			
		||||
- name: Stopping services
 | 
			
		||||
  include_tasks: down-debian.yml
 | 
			
		||||
 | 
			
		||||
- name: generate netplan config
 | 
			
		||||
  shell: netplan generate --debug
 | 
			
		||||
 | 
			
		||||
# wants a controlling terminal so it fails
 | 
			
		||||
- name: test netplan config
 | 
			
		||||
  shell: netplan try --debug --timeout=2
 | 
			
		||||
  register: test-netplan
 | 
			
		||||
  ignore_errors: True
 | 
			
		||||
 | 
			
		||||
# and does not apply this config until rebooted or ignore the above test
 | 
			
		||||
- name: Reload netplan
 | 
			
		||||
  shell: netplan apply
 | 
			
		||||
  when: not no_net_restart and test-netplan == "Configuration accepted"
 | 
			
		||||
| 
						 | 
				
			
			@ -1,23 +0,0 @@
 | 
			
		|||
{% if wan_ip != "dhcp" %}
 | 
			
		||||
network:
 | 
			
		||||
    ethernets:
 | 
			
		||||
        {{ iiab_wan_iface }}:
 | 
			
		||||
            addresses:
 | 
			
		||||
            - {{ wan_ip }}/{{ wan_cidr }}
 | 
			
		||||
            gateway4: {{ wan_gateway }}
 | 
			
		||||
            nameservers:
 | 
			
		||||
               addresses:
 | 
			
		||||
               - {{ wan_nameserver }}
 | 
			
		||||
               search:
 | 
			
		||||
               - {{ iiab_domain }}
 | 
			
		||||
            optional: true
 | 
			
		||||
    version: 2
 | 
			
		||||
{% else %}
 | 
			
		||||
network:
 | 
			
		||||
    ethernets:
 | 
			
		||||
        {{ iiab_wan_iface }}:
 | 
			
		||||
            addresses: []
 | 
			
		||||
            dhcp4: true
 | 
			
		||||
            optional: true
 | 
			
		||||
    version: 2
 | 
			
		||||
{% endif %}
 | 
			
		||||
							
								
								
									
										41
									
								
								roles/network/templates/network/netplan.j2
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								roles/network/templates/network/netplan.j2
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,41 @@
 | 
			
		|||
network:
 | 
			
		||||
    version: 2
 | 
			
		||||
{% if network_manager_active %}
 | 
			
		||||
    renderer: NetworkManager
 | 
			
		||||
{% else  %}
 | 
			
		||||
    renderer: networkd
 | 
			
		||||
{% endif %}
 | 
			
		||||
    ethernets:
 | 
			
		||||
{% if wan_ip != "dhcp" %}
 | 
			
		||||
        {{ iiab_wan_iface }}:
 | 
			
		||||
            addresses:
 | 
			
		||||
            - {{ wan_ip }}/{{ wan_cidr }}
 | 
			
		||||
            gateway4: {{ wan_gateway }}
 | 
			
		||||
            nameservers:
 | 
			
		||||
               addresses:
 | 
			
		||||
               - {{ wan_nameserver }}
 | 
			
		||||
               search:
 | 
			
		||||
               - {{ iiab_domain }}
 | 
			
		||||
            optional: true
 | 
			
		||||
{% else %}
 | 
			
		||||
        {{ iiab_wan_iface }}:
 | 
			
		||||
            addresses: []
 | 
			
		||||
            dhcp4: true
 | 
			
		||||
            optional: true
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if iiab_lan_iface == "br0" %}
 | 
			
		||||
    bridges:
 | 
			
		||||
      # the key name is the name for virtual (created) interfaces
 | 
			
		||||
        br0:
 | 
			
		||||
        # IDs of the components; switchports expands into multiple interfaces
 | 
			
		||||
        # interfaces: [switchports]
 | 
			
		||||
            # should really compute the netmask like the wan side
 | 
			
		||||
            addresses: [ {{ lan_ip }}/19]
 | 
			
		||||
            # there should really not be a gateway present testing to prove
 | 
			
		||||
            gateway4: {{ lan_ip }}
 | 
			
		||||
            nameservers:
 | 
			
		||||
                addresses: [{{ lan_ip }}]
 | 
			
		||||
            parameters:
 | 
			
		||||
                forward-delay: 0
 | 
			
		||||
                stp: false
 | 
			
		||||
{% endif %}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue