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

View File

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

View File

@ -18,7 +18,7 @@
become_user: root
block:
- 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
package:

View File

@ -14,7 +14,7 @@
# limitations under the License.
- 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
include_tasks: frr_vlans.yml

View File

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

View File

@ -25,7 +25,7 @@ frr_repos_keys:
state: present
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
filename: "frr"