Hi! So, while i do use conditions like: ansible_facts[ 'distribution' ] == 'CentOS'
now i'm trying to use ansible_all_ipv4_addresses
i have the following code:
- debug:
msg: |
ansible_all_ipv4_addresses: {{ ansible_all_ipv4_addresses }}
_network_reduced: "{{ ansible_all_ipv4_addresses | ansible.utils.reduce_on_network('XX.XXX.XX.0/24') }}"
_result_lenght: "{{ ansible_all_ipv4_addresses | ansible.utils.reduce_on_network('XX.XXX.XX.0/24') | length }}"
_result_value: "{{ ( ansible_all_ipv4_addresses | ansible.utils.reduce_on_network('XX.XXX.XX.0/24') | length | int ) > 0 }}"
- name: Chrony configuration 85
ansible.builtin.copy:
src: "{{ playbook_dir }}/../additions/chrony/chrony.conf.client_pub85"
dest: /etc/chrony.conf
mode: 0644
owner: root
group: root
backup: true
force: true
register: chrony_is_configured
when:
- ( ( ansible_facts['ansible_all_ipv4_addresses'] | ansible.utils.reduce_on_network( 'XX.XXX.XX.0/24' ) | length | int ) > 0 )
the problem is that the debug see the ansible_all_ipv4_addresses while the when condition does not
i get:
Dec 14 2022 01:18:00 - chrony_cfg.yml - - debug - OK - {"msg": "ansible_all_ipv4_addresses: ['XX.XXX.XX.21', '172.18.0.21']\n_network_reduced: \"['XX.XXX.XX.21']\"\n_result_lenght: \"1\"\n_result_value: \"True\"\n", "_ansible_verbose_always": true, "_ansible_no_log": null, "changed": false}
Dec 14 2022 01:18:00 - chrony_cfg.yml - Chrony configuration 85 - ansible.builtin.copy - FAILED - {"msg": "The conditional check '( ( ansible_facts['ansible_all_ipv4_addresses'] | ansible.utils.reduce_on_network( 'XX.XXX.XX.0/24' )
length | int ) > 0 )' failed. The error was: error while evaluating conditional (( (
ansible_facts['ansible_all_ipv4_addresses'] | ansible.utils.reduce_on_network( 'XX.XXX.XX.0/24' ) | length | int ) > 0 )): 'dict object' has no attribute 'ansible_all_ipv4_addresses'. 'dict object' has no attribute 'ansible_all_ipv4_addresses'\n\nThe error appears to be in '/home/adrian/ansible/playbooks/tasks/pkg_chrony_task.yml': line 15, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Chrony configuration 85\n ^ here\n", "_ansible_no_log": false}
so, beside that i can check in my redis backend that 'ansible_all_ipv4_addresses' is present, the fact is that
the debug task works ..
So, does anyone have any idea what is going on?
Thanks a lot!!
Adrian