Make role INJECT_FACTS_AS_VARS friendly

Enabled INJECT_FACTS_AS_VARS[1] (which is default behaviour) has very
negative impact on Ansible performance [2].

In order to be able to reduce amount of variables and performance
penalty, role is being adopted to be used with no injected facts

[1] https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_vars_facts.html#ansible-facts
[2] https://github.com/ansible/ansible/issues/73654

Change-Id: I71a326964be7597ebaad0183c3a774321885c6f5
This commit is contained in:
Dmitriy Rabotyagov 2024-02-22 12:04:08 +01:00
parent d4b8abae78
commit 32dc34c70b
6 changed files with 14 additions and 14 deletions

View File

@ -41,21 +41,21 @@ provisioner:
- ip route 10.0.0.0/24 192.168.1.10 - ip route 10.0.0.0/24 192.168.1.10
frr_bgpd_config: frr_bgpd_config:
- router bgp 1234 - router bgp 1234
- "bgp router-id {{ hostvars['primary']['ansible_' ~ bridge_name | replace('-', '_')]['ipv4']['address'] }}" - "bgp router-id {{ hostvars['primary']['ansible_facts'][bridge_name | replace('-', '_')]['ipv4']['address'] }}"
- "neighbor {{ hostvars['secondary']['ansible_' ~ bridge_name | replace('-', '_')]['ipv4']['address'] }} remote-as 5678" - "neighbor {{ hostvars['secondary']['ansible_facts'][bridge_name | replace('-', '_')]['ipv4']['address'] }} remote-as 5678"
- network 192.168.1.0/24 - network 192.168.1.0/24
- address-family ipv4 unicast - address-family ipv4 unicast
- " neighbor {{ hostvars['secondary']['ansible_' ~ bridge_name | replace('-', '_')]['ipv4']['address'] }} prefix-list pl-allowed-adv out" - " neighbor {{ hostvars['secondary']['ansible_facts'][bridge_name | replace('-', '_')]['ipv4']['address'] }} prefix-list pl-allowed-adv out"
- "exit-address-family" - "exit-address-family"
- ip prefix-list pl-allowed-adv seq 5 permit 192.168.1.0/24 - ip prefix-list pl-allowed-adv seq 5 permit 192.168.1.0/24
- ip prefix-list pl-allowed-adv seq 10 deny any - ip prefix-list pl-allowed-adv seq 10 deny any
secondary: secondary:
frr_bgpd_config: frr_bgpd_config:
- router bgp 5678 - router bgp 5678
- "bgp router-id {{ hostvars['secondary']['ansible_' ~ bridge_name | replace('-', '_')]['ipv4']['address'] }}" - "bgp router-id {{ hostvars['secondary']['ansible_facts'][bridge_name | replace('-', '_')]['ipv4']['address'] }}"
- "neighbor {{ hostvars['primary']['ansible_' ~ bridge_name | replace('-', '_')]['ipv4']['address'] }} remote-as 1234" - "neighbor {{ hostvars['primary']['ansible_facts'][bridge_name | replace('-', '_')]['ipv4']['address'] }} remote-as 1234"
- address-family ipv4 unicast - address-family ipv4 unicast
- " neighbor {{ hostvars['primary']['ansible_' ~ bridge_name | replace('-', '_')]['ipv4']['address'] }} prefix-list pl-allowed-adv in" - " neighbor {{ hostvars['primary']['ansible_facts'][bridge_name | replace('-', '_')]['ipv4']['address'] }} prefix-list pl-allowed-adv in"
- exit-address-family - exit-address-family
- ip prefix-list pl-allowed-adv seq 5 permit 192.168.1.0/24 - ip prefix-list pl-allowed-adv seq 5 permit 192.168.1.0/24
- ip prefix-list pl-allowed-adv seq 10 deny any - ip prefix-list pl-allowed-adv seq 10 deny any
@ -64,8 +64,8 @@ provisioner:
prepare: prepare.yml prepare: prepare.yml
converge: playbook.yml converge: playbook.yml
verify: verify.yml verify: verify.yml
# config_options: config_options:
# defaults: defaults:
# inject_facts_as_vars: false inject_facts_as_vars: false
scenario: scenario:
name: default name: default

View File

@ -26,7 +26,7 @@
- name: Ping vlans ip address - name: Ping vlans ip address
shell: | shell: |
set -e set -e
ping -c2 "{{ hostvars[inventory_hostname]['ansible_eth1']['ipv4']['address'] }}" ping -c2 "{{ hostvars[inventory_hostname]['ansible_facts']['eth1']['ipv4']['address'] }}"
changed_when: false changed_when: false
register: _ping_vlan register: _ping_vlan
until: _ping_vlan is success until: _ping_vlan is success

View File

@ -18,7 +18,7 @@
become_user: root become_user: root
block: block:
- name: Apply package management distro specific configuration - name: Apply package management distro specific configuration
include_tasks: "frr_install_{{ ansible_pkg_mgr | lower }}.yml" include_tasks: "frr_install_{{ ansible_facts['pkg_mgr'] | lower }}.yml"
- name: Install required distro packages - name: Install required distro packages
package: package:

View File

@ -14,7 +14,7 @@
# limitations under the License. # limitations under the License.
- name: Gather variables for each operating system - name: Gather variables for each operating system
include_vars: "{{ ansible_os_family | lower }}.yml" include_vars: "{{ ansible_facts['os_family'] | lower }}.yml"
- name: Create required vlan interfaces - name: Create required vlan interfaces
include_tasks: frr_vlans.yml include_tasks: frr_vlans.yml

View File

@ -3,7 +3,7 @@
! !
frr defaults traditional frr defaults traditional
! !
hostname {{ ansible_hostname }} hostname {{ ansible_facts['hostname'] }}
log syslog informational log syslog informational
! !
! staticd config ! staticd config

View File

@ -25,7 +25,7 @@ frr_repos_keys:
state: present state: present
frr_repos: frr_repos:
- repo: "deb {{ apt_repo_url | default('https://deb.frrouting.org/frr ' ~ ansible_distribution_release ~ ' frr-stable') }}" - repo: "deb {{ apt_repo_url | default('https://deb.frrouting.org/frr ' ~ ansible_facts['distribution_release'] ~ ' frr-stable') }}"
state: present state: present
filename: "frr" filename: "frr"