Skip to content

Commit d5c4c00

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 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. [0] https://docs.ansible.com/ansible/latest/reference_appendices/config.html#inject-facts-as-vars
1 parent b792441 commit d5c4c00

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

roles/cephadm/tasks/bootstrap.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
block:
44
- name: Bootstrap cephadm
55
vars:
6-
mon_ip: "{{ hostvars[inventory_hostname]['ansible_'~cephadm_public_interface].ipv4.address }}"
6+
mon_ip: "{{ hostvars[inventory_hostname].ansible_facts[cephadm_public_interface].ipv4.address }}"
77
monitoring_stack: "{{ '--skip-monitoring-stack' if not (cephadm_enable_monitoring | bool) else '' }}"
88
dashboard: "{{ '--skip-dashboard' if not cephadm_enable_dashboard | bool else '' }}"
99
firewalld: "{{ '--skip-firewalld' if not cephadm_enable_firewalld | bool else '' }}"

roles/cephadm/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- include_tasks: "prechecks.yml"
66
when: not cephadm_skip_prechecks | bool
77

8-
- include_tasks: "pkg_{{ ansible_os_family | lower }}.yml"
8+
- include_tasks: "pkg_{{ ansible_facts.os_family | lower }}.yml"
99

1010
- include_tasks: "prereqs.yml"
1111

roles/cephadm/tasks/osds.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
block:
44
- name: Add OSDs individually
55
command:
6-
cmd: "cephadm daemon add osd {{ ansible_hostname }}:{{ item }}"
6+
cmd: "cephadm daemon add osd {{ ansible_facts.hostname }}:{{ item }}"
77
become: true
88
when: cephadm_osd_devices | length > 0
99
with_items: "{{ cephadm_osd_devices }}"

roles/cephadm/tasks/pkg_debian.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
- name: Ensure Ceph repositories are defined
99
apt_repository:
10-
repo: "deb https://download.ceph.com/debian-{{ item }}/ {{ ansible_distribution_release }} main"
10+
repo: "deb https://download.ceph.com/debian-{{ item }}/ {{ ansible_facts.distribution_release }} main"
1111
state: "{{ 'present' if item == cephadm_ceph_release else 'absent' }}"
1212
when: not cephadm_custom_repos | bool
1313
become: true

roles/cephadm/templates/cluster.yml.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{% for host in groups['ceph'] %}
22
---
33
service_type: host
4-
hostname: {{ hostvars[host]['ansible_hostname'] }}
5-
addr: {{ hostvars[host]['ansible_'~cephadm_admin_interface]['ipv4']['address'] }}
4+
hostname: {{ hostvars[host].ansible_facts.hostname }}
5+
addr: {{ hostvars[host].ansible_facts[cephadm_admin_interface]['ipv4']['address'] }}
66
labels:
77
{% if host in groups['mons'] %}
88
- _admin

0 commit comments

Comments
 (0)