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

Fails check --list-hosts when hosts get value with a variable #75354

Closed
1 task done
fran-expertice opened this issue Jul 29, 2021 · 7 comments · Fixed by #75533
Closed
1 task done

Fails check --list-hosts when hosts get value with a variable #75354

fran-expertice opened this issue Jul 29, 2021 · 7 comments · Fixed by #75533
Assignees
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.

Comments

@fran-expertice
Copy link

fran-expertice commented Jul 29, 2021

Summary

When I trie to check hosts into playbook (flag --list-hosts), trigger a error. This playbook get the next line: host: "{{ myvar_hosts }}"

Issue Type

Bug Report

Component Name

ansible-playbook --list-hosts

Ansible Version

ansible 2.9.19
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/fran-robles/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Aug 13 2020, 02:51:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

Configuration

ansible-config dump --only-changed
COLLECTIONS_PATHS(/etc/ansible/ansible.cfg) = [u'/etc/ansible/ansible_collections']

OS / Environment

RHEL 7.9

Steps to Reproduce

ansible-playbook ping_pong.yml -i ../inventario.ini --list-hosts -vvv

Expected Results

I expected a promt for input inventory value and then show hosts or hosts-groups involve from the inventory file.

for example:

  1. After input value in var_promt (inventory)

  2. Show:

playbook: ping_pong.yml

play #1 (localhost): Ping Pong TAGS: []
pattern: [u'localhost']
hosts (1):
localhost

Actual Results

ansible-playbook 2.9.19
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/fran-robles/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible-playbook
  python version = 2.7.5 (default, Aug 13 2020, 02:51:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /opt/ansible-project/inventario.ini as it did not pass its verify_file() method
auto declined parsing /opt/ansible-project/inventario.ini as it did not pass its verify_file() method
yaml declined parsing /opt/ansible-project/inventario.ini as it did not pass its verify_file() method
Parsed /opt/ansible-project/inventario.ini inventory source with ini plugin
1 plays in ping_pong.yml
Read vars_file '../vars/external_vars.yml'
Read vars_file '../vars/external_vars.yml'

**playbook: ping_pong.yml
ERROR! Unexpected Exception, this is probably a bug:
the full traceback was:**

Traceback (most recent call last):
  File "/bin/ansible-playbook", line 123, in <module>
    exit_code = cli.run()
  File "/usr/lib/python2.7/site-packages/ansible/cli/playbook.py", line 141, in run
    msg = "\n  play #%d (%s): %s" % (idx + 1, ','.join(play.hosts), play.name)
TypeError

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibot
Copy link
Contributor

ansibot commented Jul 29, 2021

Files identified in the description:

  • lib/ansible/playbook

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

click here for bot help

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback. labels Jul 29, 2021
@bcoca
Copy link
Member

bcoca commented Jul 29, 2021

can you provide a full reproducer (the source of ping_pong.yml for example)?

needs_info

@ansibot ansibot added the needs_info This issue requires further information. Please answer any outstanding questions. label Jul 29, 2021
@fran-expertice
Copy link
Author

fran-expertice commented Jul 29, 2021

Thanks for answering.

Here:

---
- name: "Ping Pong"
  hosts: "{{ var_inventario }}"
  gather_facts: false
  remote_user: "{{ ansible_user }}"
  vars_files:
    - ../vars/external_vars.yml
  vars_prompt:
  - name: var_inventario
    prompt: "Enter host or group host stored inside inventory file"
    private: no
  tasks:
  - name: "Checking healt...."
    ansible.builtin.ping:
     data:

@ansibot ansibot removed the needs_info This issue requires further information. Please answer any outstanding questions. label Jul 29, 2021
@bcoca
Copy link
Member

bcoca commented Jul 29, 2021

--list-hosts won't execute vars_prompt,that is why the variable will be undefined unless you pass it as an extra var

@fran-expertice
Copy link
Author

okay, instead var_prompt better extra var? for now?

Can ansible evaluates --list-hosts after launch the var_prompt? to future, I mean.

regard.

@nitzmahone
Copy link
Member

The behavior is probably not going to change, but the fact that we're displaying a Traceback instead of an error message is probably a bug...

@bcoca bcoca self-assigned this Jul 29, 2021
@nitzmahone nitzmahone removed the needs_triage Needs a first human triage before being processed. label Jul 29, 2021
@bcoca
Copy link
Member

bcoca commented Jul 29, 2021

probably not, but keeping the ticket open to return a meaningful error, the current stacktrace is not acceptable

bcoca added a commit to bcoca/ansible that referenced this issue Aug 19, 2021
@ansibot ansibot added the has_pr This issue has an associated PR. label Aug 19, 2021
bcoca added a commit to bcoca/ansible that referenced this issue Aug 23, 2021
sivel pushed a commit that referenced this issue Sep 1, 2021
@ansible ansible locked and limited conversation to collaborators Sep 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. has_pr This issue has an associated PR. support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants