Skip to content

Commit 493e645

Browse files
committed
Use ansible_facts to reference facts
By default, Ansible injects a variable for every fact, prefixed with ansible_. This can result in a large number of variables for each host, which at scale can incur a performance penalty. Ansible provides a configuration option [0] that can be set to False to prevent this injection of facts. In this case, facts should be referenced via ansible_facts.<fact>. This change updates all references to Ansible facts within Kolla Ansible from using individual fact variables to using the items in the ansible_facts dictionary. This allows users to disable fact variable injection in their Ansible configuration, which may provide some performance improvement. This change disables fact variable injection in the ansible configuration used in CI, to catch any attempts to use the injected variables. [0] https://docs.ansible.com/ansible/latest/reference_appendices/config.html#inject-facts-as-vars Change-Id: I7e9d5c9b8b9164d4aee3abb4e37c8f28d98ff5d1 Partially-Implements: blueprint performance-improvements (cherry picked from commit ade5bfa)
1 parent 8c68ced commit 493e645

File tree

104 files changed

+424
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+424
-371
lines changed

ansible/gather-facts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@
3737
with_items: "{{ delegate_hosts }}"
3838
# We gathered facts for all hosts in the batch during the first play.
3939
when:
40-
- not hostvars[item].module_setup | default(false)
40+
- not hostvars[item].ansible_facts.module_setup | default(false)
4141
tags: always

ansible/group_vars/all.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,8 @@ supported_policy_format_list:
537537
multiple_regions_names:
538538
- "{{ openstack_region_name }}"
539539

540-
openstack_service_workers: "{{ [ansible_processor_vcpus, 5]|min }}"
541-
openstack_service_rpc_workers: "{{ [ansible_processor_vcpus, 3]|min }}"
540+
openstack_service_workers: "{{ [ansible_facts.processor_vcpus, 5]|min }}"
541+
openstack_service_rpc_workers: "{{ [ansible_facts.processor_vcpus, 3]|min }}"
542542

543543
# Optionally allow Kolla to set sysctl values
544544
set_sysctl: "yes"
@@ -920,7 +920,7 @@ gnocchi_metric_datadir_volume: "gnocchi"
920920
cinder_backend_ceph: "no"
921921
cinder_backend_vmwarevc_vmdk: "no"
922922
cinder_volume_group: "cinder-volumes"
923-
cinder_target_helper: "{{ 'lioadm' if ansible_os_family == 'RedHat' else 'tgtadm' }}"
923+
cinder_target_helper: "{{ 'lioadm' if ansible_facts.os_family == 'RedHat' else 'tgtadm' }}"
924924
# Valid options are [ '', redis, etcd ]
925925
cinder_coordination_backend: "{{ 'redis' if enable_redis|bool else 'etcd' if enable_etcd|bool else '' }}"
926926

ansible/post-deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
template:
88
src: "roles/common/templates/admin-openrc.sh.j2"
99
dest: "{{ node_config }}/admin-openrc.sh"
10-
owner: "{{ ansible_user_uid }}"
11-
group: "{{ ansible_user_gid }}"
10+
owner: "{{ ansible_facts.user_uid }}"
11+
group: "{{ ansible_facts.user_gid }}"
1212
mode: 0600
1313

1414
- import_role:

ansible/roles/aodh/defaults/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,26 +158,26 @@ aodh_notifier_healthcheck:
158158
aodh_api_default_volumes:
159159
- "{{ node_config_directory }}/aodh-api/:{{ container_config_directory }}/:ro"
160160
- "/etc/localtime:/etc/localtime:ro"
161-
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_os_family == 'Debian' else '' }}"
161+
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
162162
- "aodh:/var/lib/aodh/"
163163
- "kolla_logs:/var/log/kolla/"
164164
- "{{ kolla_dev_repos_directory ~ '/aodh/aodh:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/aodh' if aodh_dev_mode | bool else '' }}"
165165
aodh_evaluator_default_volumes:
166166
- "{{ node_config_directory }}/aodh-evaluator/:{{ container_config_directory }}/:ro"
167167
- "/etc/localtime:/etc/localtime:ro"
168-
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_os_family == 'Debian' else '' }}"
168+
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
169169
- "kolla_logs:/var/log/kolla/"
170170
- "{{ kolla_dev_repos_directory ~ '/aodh/aodh:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/aodh' if aodh_dev_mode | bool else '' }}"
171171
aodh_listener_default_volumes:
172172
- "{{ node_config_directory }}/aodh-listener/:{{ container_config_directory }}/:ro"
173173
- "/etc/localtime:/etc/localtime:ro"
174-
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_os_family == 'Debian' else '' }}"
174+
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
175175
- "kolla_logs:/var/log/kolla/"
176176
- "{{ kolla_dev_repos_directory ~ '/aodh/aodh:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/aodh' if aodh_dev_mode | bool else '' }}"
177177
aodh_notifier_default_volumes:
178178
- "{{ node_config_directory }}/aodh-notifier/:{{ container_config_directory }}/:ro"
179179
- "/etc/localtime:/etc/localtime:ro"
180-
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_os_family == 'Debian' else '' }}"
180+
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
181181
- "kolla_logs:/var/log/kolla/"
182182
- "{{ kolla_dev_repos_directory ~ '/aodh/aodh:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/aodh' if aodh_dev_mode | bool else '' }}"
183183

ansible/roles/barbican/defaults/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,20 @@ barbican_worker_healthcheck:
115115
barbican_api_default_volumes:
116116
- "{{ node_config_directory }}/barbican-api/:{{ container_config_directory }}/:ro"
117117
- "/etc/localtime:/etc/localtime:ro"
118-
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_os_family == 'Debian' else '' }}"
118+
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
119119
- "barbican:/var/lib/barbican/"
120120
- "kolla_logs:/var/log/kolla/"
121121
- "{{ kolla_dev_repos_directory ~ '/barbican/barbican:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/barbican' if barbican_dev_mode | bool else '' }}"
122122
barbican_keystone_listener_default_volumes:
123123
- "{{ node_config_directory }}/barbican-keystone-listener/:{{ container_config_directory }}/:ro"
124124
- "/etc/localtime:/etc/localtime:ro"
125-
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_os_family == 'Debian' else '' }}"
125+
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
126126
- "kolla_logs:/var/log/kolla/"
127127
- "{{ kolla_dev_repos_directory ~ '/barbican/barbican:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/barbican' if barbican_dev_mode | bool else '' }}"
128128
barbican_worker_default_volumes:
129129
- "{{ node_config_directory }}/barbican-worker/:{{ container_config_directory }}/:ro"
130130
- "/etc/localtime:/etc/localtime:ro"
131-
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_os_family == 'Debian' else '' }}"
131+
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
132132
- "kolla_logs:/var/log/kolla/"
133133
- "{{ kolla_dev_repos_directory ~ '/barbican/barbican:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/barbican' if barbican_dev_mode | bool else '' }}"
134134

ansible/roles/baremetal/defaults/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
enable_docker_repo: true
44

55
# Docker APT repository configuration.
6-
docker_apt_url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}"
7-
docker_apt_repo: "deb {{ docker_apt_url }} {{ ansible_distribution_release }} stable"
6+
docker_apt_url: "https://download.docker.com/linux/{{ ansible_facts.distribution | lower }}"
7+
docker_apt_repo: "deb {{ docker_apt_url }} {{ ansible_facts.distribution_release }} stable"
88
docker_apt_key_file: "gpg"
99
docker_apt_key_id: "0EBFCD88"
1010
docker_apt_package: "docker-ce"
1111

1212
# Docker Yum repository configuration.
13-
docker_yum_url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}"
13+
docker_yum_url: "https://download.docker.com/linux/{{ ansible_facts.distribution | lower }}"
1414
docker_yum_baseurl: "{{ docker_yum_url }}/$releasever/$basearch/stable"
1515
docker_yum_gpgkey: "{{ docker_yum_url }}/gpg"
1616
docker_yum_gpgcheck: true
@@ -41,7 +41,7 @@ docker_https_proxy: ""
4141
docker_no_proxy: ""
4242

4343
# Version of python used to execute Ansible modules.
44-
host_python_version: "{{ ansible_python.version.major }}.{{ ansible_python.version.minor }}"
44+
host_python_version: "{{ ansible_facts.python.version.major }}.{{ ansible_facts.python.version.minor }}"
4545

4646
debian_pkg_install:
4747
- "{{ docker_apt_package }}"

ansible/roles/baremetal/tasks/install.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
apt:
44
update_cache: yes
55
become: True
6-
when: ansible_os_family == 'Debian'
6+
when: ansible_facts.os_family == 'Debian'
77

88
# TODO(inc0): Gates don't seem to have ufw executable, check for it instead of ignore errors
99
- name: Set firewall default policy
1010
become: True
1111
ufw:
1212
state: disabled
1313
policy: allow
14-
when: ansible_os_family == 'Debian'
14+
when: ansible_facts.os_family == 'Debian'
1515
ignore_errors: yes
1616

1717
- name: Check if firewalld is installed
@@ -21,7 +21,7 @@
2121
failed_when: firewalld_check.rc > 1
2222
args:
2323
warn: false
24-
when: ansible_os_family == 'RedHat'
24+
when: ansible_facts.os_family == 'RedHat'
2525

2626
- name: Disable firewalld
2727
become: True
@@ -32,7 +32,7 @@
3232
with_items:
3333
- firewalld
3434
when:
35-
- ansible_os_family == 'RedHat'
35+
- ansible_facts.os_family == 'RedHat'
3636
- firewalld_check.rc == 0
3737

3838
# Upgrading docker engine may cause containers to stop. Take a snapshot of the
@@ -63,15 +63,15 @@
6363
state: link
6464
become: true
6565
when:
66-
- ansible_os_family == 'Debian'
66+
- ansible_facts.os_family == 'Debian'
6767
- not docker_unit_file.stat.exists
6868

6969
- name: Install apt packages
7070
package:
7171
name: "{{ (debian_pkg_install | join(' ')).split() }}"
7272
state: present
7373
become: True
74-
when: ansible_os_family == 'Debian'
74+
when: ansible_facts.os_family == 'Debian'
7575
register: apt_install_result
7676

7777
- name: Install deltarpm packages
@@ -80,15 +80,15 @@
8080
state: present
8181
update_cache: yes
8282
become: True
83-
when: ansible_os_family == 'RedHat'
83+
when: ansible_facts.os_family == 'RedHat'
8484

8585
- name: Install RPM packages
8686
package:
8787
name: "{{ (redhat_pkg_install | join(' ')).split() }}"
8888
state: present
8989
update_cache: yes
9090
become: True
91-
when: ansible_os_family == 'RedHat'
91+
when: ansible_facts.os_family == 'RedHat'
9292
register: rpm_install_result
9393

9494
# If any packages were updated, and any containers were running, wait for the
@@ -122,7 +122,7 @@
122122
- running_containers.rc == 0
123123
- running_containers.stdout != ''
124124
vars:
125-
install_result: "{{ rpm_install_result if ansible_os_family == 'RedHat' else apt_install_result }}"
125+
install_result: "{{ rpm_install_result if ansible_facts.os_family == 'RedHat' else apt_install_result }}"
126126

127127
- name: Install latest pip in the virtualenv
128128
pip:
@@ -150,11 +150,11 @@
150150
name: "{{ (ubuntu_pkg_removals | join(' ')).split() }}"
151151
state: absent
152152
become: True
153-
when: ansible_os_family == 'Debian'
153+
when: ansible_facts.os_family == 'Debian'
154154

155155
- name: Remove packages
156156
package:
157157
name: "{{ (redhat_pkg_removals | join(' ')).split() }}"
158158
state: absent
159159
become: True
160-
when: ansible_os_family == 'RedHat'
160+
when: ansible_facts.os_family == 'RedHat'

ansible/roles/baremetal/tasks/post-install.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,19 @@
192192
stat:
193193
path: /etc/apparmor.d/usr.sbin.libvirtd
194194
register: apparmor_libvirtd_profile
195-
when: ansible_distribution == "Ubuntu"
195+
when: ansible_facts.distribution == "Ubuntu"
196196

197197
- name: Get stat of libvirtd apparmor disable profile
198198
stat:
199199
path: /etc/apparmor.d/disable/usr.sbin.libvirtd
200200
register: apparmor_libvirtd_disable_profile
201-
when: ansible_distribution == "Ubuntu"
201+
when: ansible_facts.distribution == "Ubuntu"
202202

203203
- name: Remove apparmor profile for libvirt
204204
command: apparmor_parser -R /etc/apparmor.d/usr.sbin.libvirtd
205205
become: True
206206
when:
207-
- ansible_distribution == "Ubuntu"
207+
- ansible_facts.distribution == "Ubuntu"
208208
- apparmor_libvirtd_profile.stat.exists
209209
- not apparmor_libvirtd_disable_profile.stat.exists
210210

@@ -213,14 +213,14 @@
213213
path: /etc/apparmor.d/usr.sbin.chronyd
214214
register: apparmor_chronyd_profile
215215
when:
216-
- ansible_os_family == "Debian"
216+
- ansible_facts.os_family == "Debian"
217217
- enable_chrony | bool
218218

219219
- name: Remove apparmor profile for chrony
220220
command: apparmor_parser -R /etc/apparmor.d/usr.sbin.chronyd
221221
become: True
222222
when:
223-
- ansible_os_family == "Debian"
223+
- ansible_facts.os_family == "Debian"
224224
- enable_chrony | bool
225225
- apparmor_chronyd_profile.stat.exists
226226

@@ -272,7 +272,7 @@
272272
state: stopped
273273
become: True
274274
when:
275-
- ansible_os_family == "Debian"
275+
- ansible_facts.os_family == "Debian"
276276
- enable_host_ntp | bool
277277

278278
- name: Stop time service
@@ -281,7 +281,7 @@
281281
state: stopped
282282
become: True
283283
when:
284-
- ansible_os_family == "RedHat"
284+
- ansible_facts.os_family == "RedHat"
285285
- enable_host_ntp | bool
286286

287287
- name: Synchronizing time one-time
@@ -296,7 +296,7 @@
296296
enabled: yes
297297
become: True
298298
when:
299-
- ansible_os_family == "Debian"
299+
- ansible_facts.os_family == "Debian"
300300
- enable_host_ntp | bool
301301

302302
- name: Start time sync service
@@ -306,7 +306,7 @@
306306
enabled: yes
307307
become: True
308308
when:
309-
- ansible_os_family == "RedHat"
309+
- ansible_facts.os_family == "RedHat"
310310
- enable_host_ntp | bool
311311

312312
- name: Change state of selinux
@@ -316,4 +316,4 @@
316316
become: true
317317
when:
318318
- change_selinux | bool
319-
- ansible_os_family == "RedHat"
319+
- ansible_facts.os_family == "RedHat"

ansible/roles/baremetal/tasks/pre-install.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- name: Ensure hostname does not point to 127.0.1.1 in /etc/hosts
1818
lineinfile:
1919
dest: /etc/hosts
20-
regexp: "^127.0.1.1\\b.*\\s{{ ansible_hostname }}\\b"
20+
regexp: "^127.0.1.1\\b.*\\s{{ ansible_facts.hostname }}\\b"
2121
state: absent
2222
become: True
2323
when: customize_etc_hosts | bool
@@ -28,9 +28,9 @@
2828
marker: "# {mark} ANSIBLE GENERATED HOSTS"
2929
block: |
3030
{% for host in groups['baremetal'] %}
31-
{% set api_interface = hostvars[host]['api_interface'] | replace('-', '_') %}
32-
{% if host not in groups['bifrost'] or 'ansible_' + api_interface in hostvars[host] %}
33-
{% set hostnames = [hostvars[host]['ansible_nodename'], hostvars[host]['ansible_hostname']] %}
31+
{% set api_interface = hostvars[host]['api_interface'] %}
32+
{% if host not in groups['bifrost'] or api_interface in hostvars[host].ansible_facts %}
33+
{% set hostnames = [hostvars[host].ansible_facts.nodename, hostvars[host].ansible_facts.hostname] %}
3434
{{ 'api' | kolla_address(host) }} {{ hostnames | unique | join(' ') }}
3535
{% endif %}
3636
{% endfor %}
@@ -39,7 +39,7 @@
3939
- customize_etc_hosts | bool
4040
# Skip hosts in the bifrost group that do not have a valid api_interface.
4141
- inventory_hostname not in groups['bifrost'] or
42-
'ansible_' + hostvars[inventory_hostname]['api_interface'] | replace('-', '_') in hostvars[inventory_hostname]
42+
hostvars[inventory_hostname]['api_interface'] | replace('-', '_') in hostvars[inventory_hostname].ansible_facts
4343

4444
# NOTE(osmanlicilegi): The distribution might come with cloud-init installed, and manage_etc_hosts
4545
# configuration enabled. If so, it will override the file /etc/hosts from cloud-init templates at
@@ -110,7 +110,7 @@
110110
repo: "{{ docker_apt_repo }}"
111111
filename: docker
112112
become: True
113-
when: ansible_os_family == 'Debian'
113+
when: ansible_facts.os_family == 'Debian'
114114

115115
- block:
116116
- name: Ensure yum repos directory exists
@@ -147,5 +147,5 @@
147147
key: "{{ docker_yum_url }}/gpg"
148148
become: True
149149
when: docker_yum_gpgcheck | bool
150-
when: ansible_os_family == 'RedHat'
150+
when: ansible_facts.os_family == 'RedHat'
151151
when: enable_docker_repo | bool

ansible/roles/blazar/defaults/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ blazar_manager_healthcheck:
9292
blazar_api_default_volumes:
9393
- "{{ node_config_directory }}/blazar-api/:{{ container_config_directory }}/:ro"
9494
- "/etc/localtime:/etc/localtime:ro"
95-
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_os_family == 'Debian' else '' }}"
95+
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
9696
- "kolla_logs:/var/log/kolla/"
9797
- "{{ kolla_dev_repos_directory ~ '/blazar/blazar:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/blazar' if blazar_dev_mode | bool else '' }}"
9898
blazar_manager_default_volumes:
9999
- "{{ node_config_directory }}/blazar-manager/:{{ container_config_directory }}/:ro"
100100
- "/etc/localtime:/etc/localtime:ro"
101-
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_os_family == 'Debian' else '' }}"
101+
- "{{ '/etc/timezone:/etc/timezone:ro' if ansible_facts.os_family == 'Debian' else '' }}"
102102
- "kolla_logs:/var/log/kolla/"
103103
- "{{ kolla_dev_repos_directory ~ '/blazar/blazar:/var/lib/kolla/venv/lib/python' ~ distro_python_version ~ '/site-packages/blazar' if blazar_dev_mode | bool else '' }}"
104104

0 commit comments

Comments
 (0)