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

one or more %'s in /etc/ansible/facts.d value causes ansible_local to fail to load without error #82717

Open
1 task done
karlg100 opened this issue Feb 20, 2024 · 4 comments · May be fixed by #82718
Open
1 task done
Labels
affects_2.14 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module.

Comments

@karlg100
Copy link

karlg100 commented Feb 20, 2024

Summary

If a value in any local facts contains one or more "%" in the value, all ansilbe_local facts fails to populate. However, Ansible does not throw an error.

I'm unable to find this documented anywhere as expected behavior.

Issue Type

Bug Report

Component Name

local facts

Ansible Version

$ ansible --version
ansible [core 2.14.9]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.18 (main, Sep  7 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
CONFIG_FILE() = /etc/ansible/ansible.cfg

OS / Environment

RHEL9

Steps to Reproduce

  1. populate a working good local fact to /etc/ansible/facts.d/good.fact to cause ansible to populate ansible_local
[good fact]
value = this is a good fact
  1. run ansible localhost -m ansible.builtin.setup -a 'filter=ansible_local' notice ansible_local["good"]["good fact"] is populated
  2. populate bad local fact to /etc/ansible/facts.d/bad.fact
[bad fact]
value = this is a % bad % fact
  1. rerun ansible localhost -m ansible.builtin.setup -a 'filter=ansible_local' and notice no more ansible_local facts

Expected Results

before bad fact:

# ansible localhost -m ansible.builtin.setup -a 'filter=ansible_local'
localhost | SUCCESS => {
    "ansible_facts": {
        "ansible_local": {
            "good": {
                "good fact": {
                    "value": "this is a good fact"
                }
            }
        }
    },
    "changed": false
}

after bad fact:

# ansible localhost -m ansible.builtin.setup -a 'filter=ansible_local'
localhost | SUCCESS => {
    "ansible_facts": {
        "ansible_local": {
            "good": {
                "good fact": {
                    "value": "this is a good fact"
                },
                "bad fact": {
                    "value": "this is a % bad % fact"
                }
            }
        }
    },
    "changed": false
}

Actual Results

before bad fact:

# ansible localhost -m ansible.builtin.setup -a 'filter=ansible_local'
localhost | SUCCESS => {
    "ansible_facts": {
        "ansible_local": {
            "good": {
                "good fact": {
                    "value": "this is a good fact"
                }
            }
        }
    },
    "changed": false
}

after bad fact:

localhost | SUCCESS => {
    "ansible_facts": {},
    "changed": false
}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot ansibot added bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. affects_2.14 module This issue/PR relates to a module. labels Feb 20, 2024
@ansibot
Copy link
Contributor

ansibot commented Feb 20, 2024

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the component bot command.

@ansibot
Copy link
Contributor

ansibot commented Feb 20, 2024

@karlg100 ansible-core 2.14 is not supported and no longer receives bug fixes. Please test against one of the supported versions of ansible-core, preferably the most recent one, to see whether the bug has been fixed.

click here for bot help

@karlg100
Copy link
Author

reproduced on 2.15.9

# ansible --version
ansible [core 2.15.9]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.18 (main, Sep  7 2023, 00:00:00) [GCC 11.4.1 20230605 (Red Hat 11.4.1-2)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True

# ansible localhost -m ansible.builtin.setup -a 'filter=ansible_local'
localhost | SUCCESS => {
    "ansible_facts": {},
    "changed": false
}

@karlg100
Copy link
Author

karlg100 commented Feb 20, 2024

tracked down to ConfigParser call in module_utils/facts/system/local.py

when val = cp.get(sect, opt), the whole module fails without error. When running the module in debug mode, did get this error.

'%' must be followed by '%' or '(', found: '% bad % fact'

karlg100 pushed a commit to karlg100/ansible that referenced this issue Feb 20, 2024
@ansibot ansibot added the has_pr This issue has an associated PR. label Feb 20, 2024
@s-hertel s-hertel removed the needs_triage Needs a first human triage before being processed. label Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.14 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. module This issue/PR relates to a module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants