On 14.12.2022 08:05, Dick Visser wrote:
It's the other way around from what you state in the subject.
Your debug task using the variable ansible_all_ipv4_addresses, which works.
But then when of your copy task uses
ansible_facts['ansible_all_ipv4_addresses'], which gives the error.
Try using just ansible_all_ipv4_addresses in the when clause?
THANKS a lot!!! That was it!!!
i was so hunged up on using the ansible_facts like i use for OS conditions that
i did not even considered
despite the evidence show by debug module (where i considered that to be an
artefact of jinja usage)
Once again many many thanks!!
Adrian
On Wed, 14 Dec 2022 at 00:31, Adrian Sevcenco <[email protected]
<mailto:[email protected]>> wrote:
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
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to
[email protected]
<mailto:ansible-project%[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/514517aa-4361-c76a-1410-8523c13f7174%40gmail.com
<https://groups.google.com/d/msgid/ansible-project/514517aa-4361-c76a-1410-8523c13f7174%40gmail.com>.
--
Sent from Gmail Mobile
--
You received this message because you are subscribed to the Google Groups "Ansible
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
[email protected] <mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAF8BbLa-YT2JFrSgJxZPz3-yzav0V4AUz9y2T-UCmnx8grN1-A%40mail.gmail.com
<https://groups.google.com/d/msgid/ansible-project/CAF8BbLa-YT2JFrSgJxZPz3-yzav0V4AUz9y2T-UCmnx8grN1-A%40mail.gmail.com?utm_medium=email&utm_source=footer>.
--
You received this message because you are subscribed to the Google Groups "Ansible
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/d139a13f-30a1-05c9-5e3b-85fdbffebfa4%40gmail.com.