Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update_fact fails when path contains a key with a bracket in its name #349

Open
Nihlus opened this issue Apr 5, 2024 · 0 comments · May be fixed by #368
Open

update_fact fails when path contains a key with a bracket in its name #349

Nihlus opened this issue Apr 5, 2024 · 0 comments · May be fixed by #368
Assignees
Labels
bug Something isn't working

Comments

@Nihlus
Copy link

Nihlus commented Apr 5, 2024

SUMMARY

update_fact fails to update a fact where a key in the referenced path contains a bracket. In particular, I'm working with a dictionary which has a key called [runners].

ISSUE TYPE
  • Bug Report
COMPONENT NAME

update_fact

ANSIBLE VERSION
ansible [core 2.14.3]
  config file = None
  configured module search path = ['/home/jarl/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/jarl/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
# /home/jarl/.ansible/collections/ansible_collections
Collection    Version
------------- -------
ansible.utils 4.0.0  

# /usr/lib/python3/dist-packages/ansible_collections
Collection    Version
------------- -------
ansible.utils 2.9.0
CONFIGURATION
CONFIG_FILE() = None
OS / ENVIRONMENT

Debian 12 on both controller and target, python version as above

STEPS TO REPRODUCE
- hosts: 127.0.0.1
  connection: local
  tasks:
    - name: set fact
      set_fact:
        my_dict: "{{ { \"[runners]\": \"old value\" } }}"

    - name: update fact
      ansible.utils.update_fact:
        updates:
          - path: my_dict["[runners]"].value
            value: "new value"
EXPECTED RESULTS

The fact should update the given path.

ACTUAL RESULTS

The update fails, claiming it cannot find a key in my_dict called [runners (note missing closing bracket).

ansible-playbook [core 2.14.3]
  config file = None
  configured module search path = ['/home/jarl/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /home/jarl/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True
No config file found; using defaults
setting up inventory plugins
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
yaml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
ini declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Skipping due to inventory source not existing or not being readable by the current user
toml declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not
match 'all'
Loading collection ansible.utils from /home/jarl/.ansible/collections/ansible_collections/ansible/utils
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python3/dist-packages/ansible/plugins/callback/default.py
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: playbook.yml *********************************************************************************************
Positional arguments: playbook.yml
verbosity: 4
connection: smart
timeout: 10
become_method: sudo
tags: ('all',)
inventory: ('/etc/ansible/hosts',)
forks: 5
1 plays in playbook.yml

PLAY [127.0.0.1] ***************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************
task path: /home/jarl/playbook.yml:1
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: jarl
<127.0.0.1> EXEC /bin/sh -c 'echo ~jarl && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/jarl/.ansible/tmp `"&& mkdir "` echo /home/jarl/.ansible/tmp/ansible-tmp-1712307002.7893507-88412-109018197604426 `" && echo ansible-tmp-1712307002.7893507-88412-109018197604426="` echo /home/jarl/.ansible/tmp/ansible-tmp-1712307002.7893507-88412-109018197604426 `" ) && sleep 0'
Using module file /usr/lib/python3/dist-packages/ansible/modules/setup.py
<127.0.0.1> PUT /home/jarl/.ansible/tmp/ansible-local-8840847f5qwh8/tmpvorlhftj TO /home/jarl/.ansible/tmp/ansible-tmp-1712307002.7893507-88412-109018197604426/AnsiballZ_setup.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/jarl/.ansible/tmp/ansible-tmp-1712307002.7893507-88412-109018197604426/ /home/jarl/.ansible/tmp/ansible-tmp-1712307002.7893507-88412-109018197604426/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/jarl/.ansible/tmp/ansible-tmp-1712307002.7893507-88412-109018197604426/AnsiballZ_setup.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/jarl/.ansible/tmp/ansible-tmp-1712307002.7893507-88412-109018197604426/ > /dev/null 2>&1 && sleep 0'
ok: [127.0.0.1]

TASK [set fact] ****************************************************************************************************
task path: /home/jarl/playbook.yml:4
ok: [127.0.0.1] => {
    "ansible_facts": {
        "my_dict": {
            "[runners]": "old value"
        }
    },
    "changed": false
}

TASK [update fact] *************************************************************************************************
task path: /home/jarl/playbook.yml:8
The full traceback is:
Traceback (most recent call last):
  File "/home/jarl/.ansible/collections/ansible_collections/ansible/utils/plugins/action/update_fact.py", line 121, in set_value
    new_obj = obj[first]
              ~~~^^^^^^^
KeyError: '[runners'
fatal: [127.0.0.1]: FAILED! => {
    "changed": false,
    "msg": "Error: the key '[runners' was not found in {'[runners]': 'old value'}."
}

PLAY RECAP *********************************************************************************************************
127.0.0.1                  : ok=2    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   


@Ruchip16 Ruchip16 self-assigned this Apr 10, 2024
@Ruchip16 Ruchip16 added the bug Something isn't working label Apr 10, 2024
@eberna eberna linked a pull request Aug 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants