Merge "Use ansible_facts[] instead of fact variables"

This commit is contained in:
Zuul 2021-02-25 13:30:32 +00:00 committed by Gerrit Code Review
commit b812fff93a
3 changed files with 51 additions and 51 deletions

View File

@ -45,10 +45,10 @@
- name: Update initramfs
command: "{{ systemd_networkd_update_initramfs }}"
when:
- ansible_virtualization_type != "systemd-nspawn"
- ansible_virtualization_type != "lxc"
- ansible_virtualization_type != "lxd"
- ansible_virtualization_type != "podman"
- ansible_virtualization_type != "docker"
- ansible_virtualization_type != "systemd_container"
- ansible_virtualization_type != "container"
- ansible_facts['virtualization_type'] != "systemd-nspawn"
- ansible_facts['virtualization_type'] != "lxc"
- ansible_facts['virtualization_type'] != "lxd"
- ansible_facts['virtualization_type'] != "podman"
- ansible_facts['virtualization_type'] != "docker"
- ansible_facts['virtualization_type'] != "systemd_container"
- ansible_facts['virtualization_type'] != "container"

View File

@ -17,11 +17,11 @@
include_vars: "{{ item }}"
with_first_found:
- files:
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}.yml"
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml"
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
- "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
- "{{ ansible_facts['distribution'] | lower }}.yml"
- "{{ ansible_facts['os_family'] | lower }}.yml"
skip: true
tags:
- always
@ -35,16 +35,16 @@
mode: '0644'
with_items: "{{ systemd_networkd_package_repos_keys | selectattr('keyfile','defined') | list }}"
when:
- ansible_os_family | lower == 'redhat'
- ansible_distribution_major_version is version('8', '>=')
- ansible_facts['os_family'] | lower == 'redhat'
- ansible_facts['distribution_major_version'] is version('8', '>=')
- name: Ensure GPG keys have the correct SELinux contexts applied
command: restorecon -Rv /etc/pki/rpm-gpg/
# TODO(evrardjp): Be more idempotent
changed_when: false
when:
- ansible_os_family | lower == 'redhat'
- ansible_distribution_major_version is version('8', '>=')
- ansible_facts['os_family'] | lower == 'redhat'
- ansible_facts['distribution_major_version'] is version('8', '>=')
# Handle gpg keys manually
- name: Install gpg keys
@ -60,14 +60,14 @@
retries: 5
delay: 2
when:
- ansible_os_family | lower == 'redhat'
- ansible_distribution_major_version is version('8', '>=')
- ansible_facts['os_family'] | lower == 'redhat'
- ansible_facts['distribution_major_version'] is version('8', '>=')
# NOTE(jrosser) this repo is configured with the path to the first gpg key provided
- name: Install the EPEL repository
yum_repository:
name: epel-networkd
baseurl: "{{ systemd_networkd_epel_mirror ~ '/' ~ ansible_distribution_major_version ~ '/Everything/' ~ ansible_architecture }}"
baseurl: "{{ systemd_networkd_epel_mirror ~ '/' ~ ansible_facts['distribution_major_version'] ~ '/Everything/' ~ ansible_facts['architecture'] }}"
description: 'Extra Packages for Enterprise Linux $releasever - $basearch'
gpgkey: "file://{{ systemd_networkd_package_repos_keys[0].key }}"
gpgcheck: yes
@ -75,8 +75,8 @@
state: present
includepkgs: 'systemd-networkd'
when:
- ansible_os_family | lower == 'redhat'
- ansible_distribution_major_version is version('8', '>=')
- ansible_facts['os_family'] | lower == 'redhat'
- ansible_facts['distribution_major_version'] is version('8', '>=')
register: install_epel_repo
until: install_epel_repo is success
retries: 5
@ -86,8 +86,8 @@
package:
name: "{{ systemd_networkd_distro_packages }}"
state: "present"
update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}"
cache_valid_time: "{{ (ansible_pkg_mgr == 'apt') | ternary(600, omit) }}"
update_cache: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('yes', omit) }}"
cache_valid_time: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary(600, omit) }}"
enablerepo: "{{ systemd_networkd_enablerepo | default(omit) }}"
when:
- systemd_networkd_distro_packages | length > 0
@ -207,5 +207,5 @@
reload: yes
with_indexed_items: "{{ systemd_networks }}"
when:
- (ansible_os_family | lower) == 'redhat'
- (ansible_facts['os_family'] | lower) == 'redhat'
- item.1.ipforward | default(false) | bool

View File

@ -70,7 +70,7 @@
- interface: "br-dummy"
address: "10.0.0.100"
netmask: "255.255.255.0"
gateway: "{{ ansible_default_ipv4.gateway | default('10.0.0.1') }}"
gateway: "{{ ansible_facts['default_ipv4']['gateway'] | default('10.0.0.1') }}"
mtu: 9000
usedns: true
static_routes:
@ -101,34 +101,34 @@
- name: Interface check
assert:
that:
- ansible_dummy0['active']
- ansible_dummy0['type'] == 'ether'
- ansible_dummy0['mtu'] == 9000
- ansible_dummy1['active']
- ansible_dummy1['type'] == 'ether'
- ansible_dummy1['mtu'] == 9000
- ansible_dummy2['active']
- ansible_dummy2['type'] == 'ether'
- ansible_facts['dummy0']['active']
- ansible_facts['dummy0']['type'] == 'ether'
- ansible_facts['dummy0']['mtu'] == 9000
- ansible_facts['dummy1']['active']
- ansible_facts['dummy1']['type'] == 'ether'
- ansible_facts['dummy1']['mtu'] == 9000
- ansible_facts['dummy2']['active']
- ansible_facts['dummy2']['type'] == 'ether'
- name: Bond check
assert:
that:
- ansible_bond0['active']
- ansible_bond0['type'] == 'bonding'
- ansible_bond0['mtu'] == 9000
- ansible_facts['bond0']['active']
- ansible_facts['bond0']['type'] == 'bonding'
- ansible_facts['bond0']['mtu'] == 9000
- name: Bridge check
assert:
that:
- ansible_br_dummy['active']
- ansible_br_dummy['type'] == 'bridge'
- ansible_br_dummy['ipv4']['address'] == '10.0.0.100'
- ansible_br_dummy['ipv4']['netmask'] == '255.255.255.0'
- ansible_facts['br_dummy']['active']
- ansible_facts['br_dummy']['type'] == 'bridge'
- ansible_facts['br_dummy']['ipv4']['address'] == '10.0.0.100'
- ansible_facts['br_dummy']['ipv4']['netmask'] == '255.255.255.0'
- name: Bridge check
assert:
that:
- ansible_br_test['active']
- ansible_br_test['type'] == 'bridge'
- ansible_br_test['ipv4']['address'] == '10.1.0.1'
- ansible_br_test['ipv4']['netmask'] == '255.255.255.0'
- ansible_facts['br_test']['active']
- ansible_facts['br_test']['type'] == 'bridge'
- ansible_facts['br_test']['ipv4']['address'] == '10.1.0.1'
- ansible_facts['br_test']['ipv4']['netmask'] == '255.255.255.0'
- name: Check link config overrides
shell: 'grep -wo "Alias" /etc/systemd/network/*br-dummy.link'
changed_when: false
@ -158,16 +158,16 @@
- name: Interface check
assert:
that:
- ansible_br_test is defined
- ansible_dummy2['active']
- ansible_dummy2['type'] == 'ether'
- ansible_facts['br_test'] is defined
- ansible_facts['dummy2']['active']
- ansible_facts['dummy2']['type'] == 'ether'
- name: Bridge check
assert:
that:
- ansible_br_test['active']
- ansible_br_test['type'] == 'bridge'
- ansible_br_test['ipv4']['address'] == '10.1.0.1'
- ansible_br_test['ipv4']['netmask'] == '255.255.255.0'
- ansible_facts['br_test']['active']
- ansible_facts['br_test']['type'] == 'bridge'
- ansible_facts['br_test']['ipv4']['address'] == '10.1.0.1'
- ansible_facts['br_test']['ipv4']['netmask'] == '255.255.255.0'
vars:
systemd_interface_cleanup: true
systemd_run_networkd: yes