Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nova/core/galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace: nova
name: core
version: 11.5.0
version: 11.5.1
readme: README.md
authors:
- https://github.com/novateams
Expand Down
33 changes: 24 additions & 9 deletions nova/core/roles/configure_networking/tasks/proxmox/netplan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
become: false
delegate_to: localhost
block:
- name: Templating network configuration to localhost...
- name: Templating netplan configuration files...
ansible.builtin.template:
src: netplan.yml
dest: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_netplan.yml
lstrip_blocks: true
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: "0644"
lstrip_blocks: true
loop_control:
label: "{{ item.src }}"
loop:
- src: 70-persistent-net.rules
dest: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_70-persistent-net.rules
- src: netplan.yml
dest: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_netplan.yml

- name: Getting network configuration file contents...
- name: Getting configuration files' contents
ansible.builtin.slurp:
path: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_netplan.yml
path: "{{ item }}"
register: file_contents
loop:
- /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_70-persistent-net.rules
- /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_netplan.yml

- name: Removing any existing netplan configurations...
ansible.builtin.uri:
Expand All @@ -33,18 +43,23 @@
- name: Including command run check task...
ansible.builtin.include_tasks: command_run_check.yml

- name: Writing netplan configuration to {{ custom_vm_name | default(vm_name) }}...
- name: Writing network configuration to {{ custom_vm_name | default(vm_name) }}...
ansible.builtin.uri:
url: "{{ proxmox_api_url }}/nodes/{{ cfg_net_proxmox_node }}/qemu/{{ cfg_net_proxmox_vmid }}/agent/file-write"
headers:
Authorization: PVEAPIToken={{ proxmox_defaults.api_user }}!{{ proxmox_defaults.api_token_id }}={{ proxmox_defaults.api_token_secret }}
method: POST
body:
content: "{{ file_contents.content | b64decode }}"
file: /etc/netplan/01-netcfg.yaml
content: "{{ file_contents.results[file_index].content | b64decode }}"
file: "{{ item }}"
body_format: json
validate_certs: "{{ proxmox_defaults.validate_certs }}"
register: network_config_command
loop_control:
index_var: file_index
loop:
- /etc/udev/rules.d/70-persistent-net.rules
- /etc/netplan/01-netcfg.yaml

- name: Applying netplan...
ansible.builtin.uri:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@
command:
- sh
- -c
- "systemctl enable systemd-networkd && systemctl restart systemd-networkd &&
systemctl enable systemd-udev-trigger && systemctl restart systemd-udev-trigger"
- "systemctl enable systemd-networkd --now && systemctl enable systemd-udev-trigger --now"
body_format: json
validate_certs: "{{ proxmox_defaults.validate_certs }}"
register: network_config_command
Expand Down Expand Up @@ -170,7 +169,7 @@
command:
- sh
- -c
- "update-initramfs -u"
- "apt purge dhcpcd-base -y && update-initramfs -u"
body_format: json
validate_certs: "{{ proxmox_defaults.validate_certs }}"
register: network_config_command
Expand Down
150 changes: 33 additions & 117 deletions nova/core/roles/configure_networking/tasks/vsphere/netplan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@
become: false
delegate_to: localhost
block:
- name: Templating network netplan.yml...
- name: Templating netplan configuration files...
ansible.builtin.template:
src: netplan.yml
dest: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_netplan.yml
lstrip_blocks: true
src: "{{ item.src }}"
dest: "{{ item.dest }}"
mode: "0644"

- name: Getting file info...
lstrip_blocks: true
loop_control:
label: "{{ item.src }}"
loop:
- src: 70-persistent-net.rules
dest: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_70-persistent-net.rules
- src: netplan.yml
dest: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_netplan.yml

- name: Getting configuration files' info...
ansible.builtin.stat:
path: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_netplan.yml
path: "{{ item }}"
register: file_size
loop:
- /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_70-persistent-net.rules
- /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_netplan.yml

# Since the vSphere API can be quite unstable especially under load, we implement a rescue loop here
# to retry the network configuration up to 3 times before failing the task completely.
Expand All @@ -30,12 +40,17 @@
spec:
attributes:
overwrite: true
size: "{{ file_size.stat.size }}"
path: /etc/netplan/01-netcfg.yaml
size: "{{ file_size.results[file_index].stat.size }}"
path: "{{ item }}"
status_code: 201
body_format: json
validate_certs: "{{ validate_vmware_certs }}"
validate_certs: "{{ vmware_defaults.validate_certs }}"
register: file_upload_prep
loop_control:
index_var: file_index
loop:
- /etc/udev/rules.d/70-persistent-net.rules
- /etc/netplan/01-netcfg.yaml

- name: Removing existing netplan configuration file(s)...
ansible.builtin.uri:
Expand All @@ -58,14 +73,19 @@

- name: Uploading file...
ansible.builtin.uri:
url: "{{ file_upload_prep.json }}"
url: "{{ file_upload_prep.results[file_upload_index].json }}"
method: PUT
headers:
vmware-api-session-id: "{{ vcenter_session_api_key.json }}"
src: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_netplan.yml
src: "{{ item }}"
status_code: 200
body_format: json
validate_certs: "{{ validate_vmware_certs }}"
validate_certs: "{{ vmware_defaults.validate_certs }}"
loop_control:
index_var: file_upload_index
loop:
- /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_70-persistent-net.rules
- /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_netplan.yml

- name: Configuring network...
ansible.builtin.uri:
Expand Down Expand Up @@ -102,107 +122,3 @@

- name: Re-including vSphere network configuration tasks...
ansible.builtin.include_tasks: main.yml

# When using many IPs on a single interface, netplan will start having DNS resolution issues
# For those use cases we will use resolv.conf to configure DNS
- name: Configuring resolv.conf for multi-ip systems...
when: extra_ipv4 is defined
or extra_ipv6 is defined
block:
- name: Templating resolv.conf configuration script...
ansible.builtin.template:
src: resolv.conf
dest: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_resolv.conf
lstrip_blocks: true
mode: "0644"

- name: Getting resolv.conf file info...
ansible.builtin.stat:
path: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_resolv.conf
register: resolv_file_size

# Since the vSphere API can be quite unstable especially under load, we implement a rescue loop here
# to retry the network configuration up to 3 times before failing the task completely.
- name: Including network configuration tasks...
block:
- name: Disabling systemd-resolved service...
ansible.builtin.uri:
url: https://{{ vmware_defaults.hostname }}/api/vcenter/vm/{{ configure_networking_vsphere_vm_id }}/guest/processes?action=create
method: POST
headers:
vmware-api-session-id: "{{ vcenter_session_api_key.json }}"
body:
credentials: "{{ rest_api_credentials }}"
spec:
arguments: -c "systemctl disable --now systemd-resolved"
path: /bin/bash
status_code: 201
body_format: json
validate_certs: "{{ validate_vmware_certs }}"
register: network_config_command

- name: Including command run check task...
ansible.builtin.include_tasks: command_run_check.yml

- name: Removing existing resolv.conf file...
ansible.builtin.uri:
url: https://{{ vmware_defaults.hostname }}/api/vcenter/vm/{{ configure_networking_vsphere_vm_id }}/guest/processes?action=create
method: POST
headers:
vmware-api-session-id: "{{ vcenter_session_api_key.json }}"
body:
credentials: "{{ rest_api_credentials }}"
spec:
arguments: -c "rm -f /etc/resolv.conf"
path: /bin/bash
status_code: 201
body_format: json
validate_certs: "{{ validate_vmware_certs }}"
register: network_config_command

- name: Including command run check task...
ansible.builtin.include_tasks: command_run_check.yml

- name: Preparing resolv.conf upload...
ansible.builtin.uri:
url: https://{{ vmware_defaults.hostname }}/api/vcenter/vm/{{ configure_networking_vsphere_vm_id }}/guest/filesystem?action=create
method: POST
headers:
vmware-api-session-id: "{{ vcenter_session_api_key.json }}"
body:
credentials: "{{ rest_api_credentials }}"
spec:
attributes:
overwrite: true
size: "{{ resolv_file_size.stat.size }}"
path: /etc/resolv.conf
status_code: 201
body_format: json
validate_certs: "{{ validate_vmware_certs }}"
register: resolv_file_upload_prep

- name: Uploading resolv.conf...
ansible.builtin.uri:
url: "{{ resolv_file_upload_prep.json }}"
method: PUT
headers:
vmware-api-session-id: "{{ vcenter_session_api_key.json }}"
src: /tmp/{{ project_fullname | default('') }}_{{ inventory_hostname }}_resolv.conf
status_code: 200
body_format: json
validate_certs: "{{ validate_vmware_certs }}"

rescue:
- name: NETWORK CONFIGURATION ERROR
ansible.builtin.fail:
msg: |
Network configuration has failed {{ configure_networking_rescue_count | default(0) }} times.
Check the errors above and {{ inventory_hostname }} host logs for more details.
when: configure_networking_rescue_count | default(0) | int == 3

- name: Setting rescue loop count...
ansible.builtin.set_fact:
configure_networking_rescue_count: "{{ configure_networking_rescue_count | default(0) | int + 1 }}"

- name: Re-including vSphere network configuration tasks...
ansible.builtin.include_tasks: main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@
body:
credentials: "{{ rest_api_credentials }}"
spec:
arguments:
-c "systemctl enable systemd-networkd && systemctl restart systemd-networkd &&
systemctl enable systemd-udev-trigger && systemctl restart systemd-udev-trigger"
arguments: -c "systemctl enable systemd-networkd --now && systemctl enable systemd-udev-trigger --now"
path: /bin/bash
status_code: 201
body_format: json
Expand Down Expand Up @@ -230,7 +228,8 @@
body:
credentials: "{{ rest_api_credentials }}"
spec:
arguments: -c "update-initramfs -u"
# Removal of the dhcpcd-base package to avoid it overwriting the /etc/resolv.conf
arguments: -c "apt purge dhcpcd-base -y && update-initramfs -u"
path: /bin/bash
status_code: 201
body_format: json
Expand Down
7 changes: 1 addition & 6 deletions nova/core/roles/configure_networking/templates/netplan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ network:
{% endif %}
{% endfor %}
{% endif %}
{% if extra_ipv4 is defined or extra_ipv6 is defined %}
{{ '# Since one of the interfaces contains multiple IP addresses,' }}
{{ '# The DNS servers are configured in /etc/resolv.conf' }}
{% else %}
{% if ((interface.connection) or (interface.egress)) and (dns_server_combined != []) %}
{% if interface.egress and dns_server_combined != [] %}
nameservers:
addresses:
{% if (dns_servers != []) and (interface.addresses | map(attribute='mode') | regex_search(".*ipv4.*")) %}
Expand All @@ -84,5 +80,4 @@ network:
- {{ domain }}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
9 changes: 5 additions & 4 deletions nova/core/roles/configure_package_mirrors/tasks/debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
mode: "0644"
when: not apt_backup_file.stat.exists

- name: Removing legacy /etc/apt/sources.list file...
ansible.builtin.file:
path: /etc/apt/sources.list
state: absent
- name: Emptying the legacy /etc/apt/sources.list file...
ansible.builtin.copy:
content: ""
dest: /etc/apt/sources.list
mode: "0644"

- name: Getting {{ inventory_hostname }} architecture...
ansible.builtin.command: dpkg --print-architecture
Expand Down
9 changes: 5 additions & 4 deletions nova/core/roles/configure_package_mirrors/tasks/kali.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
mode: "0644"
when: not apt_backup_file.stat.exists

- name: Removing legacy /etc/apt/sources.list file...
ansible.builtin.file:
path: /etc/apt/sources.list
state: absent
- name: Emptying the legacy /etc/apt/sources.list file...
ansible.builtin.copy:
content: ""
dest: /etc/apt/sources.list
mode: "0644"

- name: Getting {{ inventory_hostname }} architecture...
ansible.builtin.command: dpkg --print-architecture
Expand Down
9 changes: 5 additions & 4 deletions nova/core/roles/configure_package_mirrors/tasks/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
mode: "0644"
when: not apt_backup_file.stat.exists

- name: Removing legacy /etc/apt/sources.list file...
ansible.builtin.file:
path: /etc/apt/sources.list
state: absent
- name: Emptying the legacy /etc/apt/sources.list file...
ansible.builtin.copy:
content: ""
dest: /etc/apt/sources.list
mode: "0644"

- name: Getting {{ inventory_hostname }} architecture...
ansible.builtin.command: dpkg --print-architecture
Expand Down
2 changes: 1 addition & 1 deletion nova/core/roles/coredns/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
mode: "0644"
register: coredns_template_results
loop:
- src: corefile
- src: "{{ coredns_corefile }}"
dest: "{{ coredns_config_folder }}/Corefile"

- src: docker-compose.yml
Expand Down
9 changes: 1 addition & 8 deletions nova/core/roles/docker/tasks/debian_os_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
- name: Installing Docker on Debian based OS...
when: ansible_facts.distribution not in docker_non_default_debian_os_list
block:
- name: Downloading Docker repo key for {{ ansible_facts.distribution }}...
ansible.builtin.get_url:
url: "{{ docker_apt_proxy | lower }}/gpg"
dest: /etc/apt/trusted.gpg.d/docker.asc
mode: "0644"
timeout: 60

- name: Getting {{ inventory_hostname }} architecture...
ansible.builtin.command: dpkg --print-architecture
changed_when: false
Expand All @@ -23,7 +16,7 @@
uris: "{{ docker_apt_proxy | lower }}"
suites: ["{{ ansible_facts.distribution_release | lower }}"]
components: [stable]
signed_by: /etc/apt/trusted.gpg.d/docker.asc
signed_by: "{{ docker_apt_proxy | lower }}/gpg"

- name: Removing legacy Docker repository...
ansible.builtin.file:
Expand Down
Loading