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

private_role_vars=yes prevents to import roles using vars from the parent role #57477

Closed
kvaps opened this issue Jun 6, 2019 · 2 comments
Closed
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. utilities Utilities category

Comments

@kvaps
Copy link
Contributor

kvaps commented Jun 6, 2019

SUMMARY

private_role_vars=yes prevents to import roles using vars from the parent role

ISSUE TYPE
  • Bug Report
COMPONENT NAME

import_role

ANSIBLE VERSION
ansible 2.8.0
  config file = /tmp/bug-57477/ansible.cfg
  configured module search path = ['/home/kvaps/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.3 (default, Mar 26 2019, 21:43:19) [GCC 8.2.1 20181127]
CONFIGURATION
DEFAULT_PRIVATE_ROLE_VARS(/tmp/bug-57477/ansible.cfg) = True
OS / ENVIRONMENT
Arch Linux
STEPS TO REPRODUCE
mkdir /tmp/bug-57477
cd /tmp/bug-57477
mkdir -p roles/{go_walk,print_string}/tasks

cat > roles/print_string/tasks/main.yaml <<EOT
- debug:
    var: string
EOT

cat > roles/go_walk/tasks/main.yaml <<EOT
- import_role:
    name: print_string
  vars:
    string: "{{ user }} went for a walk"
EOT

cat > plabook.yaml <<EOT
- hosts: localhost
  gather_facts: false
  roles:

  - name: go_walk
    vars:
      user: "Leo Tolstoi"
EOT

cat > ansible.cfg <<EOT
[defaults]
private_role_vars   = yes
EOT

ansible-playbook plabook.yaml
EXPECTED RESULTS

print_string role should inherit var string="Leo Tolstoi went for a walk" because this var is intentionally specified for the import_role task

ok: [localhost] => {
    "string": "Leo Tolstoi went for a walk"
}
ACTUAL RESULTS

print_string does not see var string because it contains variable from the parent role

ok: [localhost] => {
    "string": "VARIABLE IS NOT DEFINED!"
}
@kvaps
Copy link
Contributor Author

kvaps commented Jun 6, 2019

Workaround to avoid this behavior is to assign this variables before using set_fact module and remove afterwards:

cat > roles/go_walk/tasks/main.yaml <<EOT
- block:
  - set_fact:
      user: "{{ user }}"
  - import_role:
      name: print_string
    vars:
      string: "{{ user }} went for a walk"
  always:
  - set_fact:
      user: Null
EOT

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. module This issue/PR relates to a module. utilities Utilities category labels Jun 6, 2019
@bcoca bcoca added needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Jun 6, 2019
@sivel
Copy link
Member

sivel commented Feb 3, 2022

This issue was resolved in bd03fa8 and included in v2.12

If you have further questions please stop by IRC or the mailing list:

@sivel sivel closed this as completed Feb 3, 2022
@sivel sivel removed the needs_verified This issue needs to be verified/reproduced by maintainer label Feb 3, 2022
@ansible ansible locked and limited conversation to collaborators Feb 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. utilities Utilities category
Projects
None yet
Development

No branches or pull requests

4 participants