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

import_role & include_role do not process variables in parameters #32503

Closed
tima opened this issue Nov 2, 2017 · 11 comments
Closed

import_role & include_role do not process variables in parameters #32503

tima opened this issue Nov 2, 2017 · 11 comments
Assignees
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. include_role module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@tima
Copy link
Contributor

tima commented Nov 2, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME

include_role, import_role

ANSIBLE VERSION
ansible 2.4.1.0
  config file = /path/to/ansible.cfg
  configured module search path = [u'/Users/tima/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/tima/virtualenvs/ansible-2.4.1/lib/python2.7/site-packages/ansible
  executable location = /Users/tima/virtualenvs/ansible-2.4.1/bin/ansible
  python version = 2.7.10 (default, Jul 13 2015, 12:05:58) [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
CONFIGURATION

None

OS / ENVIRONMENT

Mac OS 10.10.5

SUMMARY

Using a variable in tasks_from in an include_role or import_role task is not recognized and interpreted.

STEPS TO REPRODUCE
---
- name: Deploy sampleapp
  hosts: localhost
  connection: local
  gather_facts: no
  tasks:
    - import_role:
        name: sampleapp
        tasks_from: "{{ my_action }}"
EXPECTED RESULTS

With the my_action var set thru the extra vars, the corresponding task file in the role would be executed.

ACTUAL RESULTS

Error message that the task file cannot be found.

ansible-playbook main.yml -e "my_action=provision.yml"
Using /path/to/ansible.cfg as config file
ERROR! Could not find specified file in role: tasks/{{ my_action }}
@bcoca bcoca assigned bcoca and jimi-c and unassigned bcoca Nov 2, 2017
@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Nov 2, 2017
@thaumos thaumos added this to Nice to have in 2.4.x Blocker List Nov 2, 2017
@nitzmahone nitzmahone removed the needs_triage Needs a first human triage before being processed. label Nov 2, 2017
@ansibot
Copy link
Contributor

ansibot commented Nov 18, 2017

Files identified in the description:

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

click here for bot help

@pruneau628
Copy link

pruneau628 commented Dec 6, 2017

It

also does not work with ansible-defined variables.

ansible 2.4.2.0
  config file = /Users/<redacted>/ansible.cfg
  configured module search path = [u'/usr/share/library']
  ansible python module location = /usr/local/lib/python2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.14 (default, Sep 25 2017, 09:54:19) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]

OS: mac OS X high sierra 10.13.1
Sample playbook:

---
#
- hosts: coordinators
  tasks:

    - name: Prepping inventory of coordinators
      setup:

- hosts: web-cluster
  tasks:

    - name: Prepping inventory of kubernetes cluster
      setup:

    - name: TODOREMOVE
      debug: var=ansible_distribution

    - name: web packages installation
      include_role:
        name: web
        tasks_from: "install_{{ansible_distribution}}.yml"

Invariably returns a:

TASK [web packages installation] *****************************************************************************************************************************************************************************************************************************************
task path: /<redacted>/web.yml:16
ERROR! Could not find specified file in role: tasks/install_{{ansible_distribution}}.yml

Note: this can be circumvented by making use of the dynamic include at the role-level, instead of the playbook-level.

@kiorky
Copy link
Contributor

kiorky commented Dec 17, 2017

I think #32565 may fix your bug which seems related to #21890

On my fork, you have two branchs for you:

Pristine 2.5+the PR #32565 commits: https://github.com/corpusops/ansible/tree/devel
Pristine 2.4+the PR #32565 commits: https://github.com/corpusops/ansible/tree/a2.4

@abadger abadger moved this from Nice to have to Next release in 2.4.x Blocker List Jan 19, 2018
@abadger abadger moved this from Next release to Nice to have in 2.4.x Blocker List Feb 1, 2018
@jctanner
Copy link
Contributor

possibly related #36372

@jctanner
Copy link
Contributor

According to my testing, this is fixed ...

version rc
v2.3.2.0-1 4
v2.3.3.0-0.1.rc1 4
v2.3.3.0-0.2.rc2 4
v2.3.3.0-0.3.rc3 4
v2.3.3.0-1 4
v2.4.0.0-0.1.rc1 4
v2.4.0.0-0.2.rc2 4
v2.4.0.0-0.3.rc3 4
v2.4.0.0-0.4.rc4 4
v2.4.0.0-0.5.rc5 4
v2.4.0.0-1 4
v2.4.1.0-0.3.rc1 2
v2.4.1.0-0.4.rc2 2
v2.4.1.0-1 2
v2.4.2.0-0.5.rc1 2
v2.4.2.0-1 2
v2.4.3.0-0.4.rc1 2
v2.4.3.0-0.5.rc2 2
v2.4.3.0-0.6.rc3 2
v2.4.3.0-1 2
v2.5.0b1 0
v2.5.0b2 0
devel-edaeb69a35 0

@jctanner
Copy link
Contributor

I don't see any integration tests that cover this usage pattern, so leaving this open till those are done.

@samdoran
Copy link
Contributor

This is working in devel but only with include_role, not import_role.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 1, 2018
@navidnadali
Copy link

Hi all, Any one aware of any workarounds until this is all ready?

@bcoca
Copy link
Member

bcoca commented Mar 12, 2018

@samdoran import_X won't work with host vars, include_X must be used in those cases.

@samdoran
Copy link
Contributor

samdoran commented Mar 22, 2018

I removed the import_role test using host vars. Once those tests are merged, we can close this as resolved since we have tests of the inclued_role use case brought up by this issue.

@samdoran
Copy link
Contributor

Closing now that we have integration tests for this use case.

samdoran added a commit that referenced this issue Mar 23, 2018
…37742)

* Add tests using a variable in tasks_from field

Related to #32503

* Do not test using hostvars with import_role

hostvars cannot be used with import_role — use include_role instead
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. include_role module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
No open projects
Development

No branches or pull requests