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

Support vars_files when using import_playbook #36806

Closed
jlsalmon opened this issue Feb 27, 2018 · 8 comments
Closed

Support vars_files when using import_playbook #36806

jlsalmon opened this issue Feb 27, 2018 · 8 comments
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bot_closed feature This issue/PR relates to a feature request. has_pr This issue has an associated PR. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. utilities Utilities category

Comments

@jlsalmon
Copy link

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

import_playbook

ANSIBLE VERSION
ansible 2.4.2.0
  config file = /opt/rhel-ansible/ansible.cfg
  configured module search path = [u'/home/jsalmon/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, May  3 2017, 07:55:04) [GCC 4.8.5 20150623 (Red Hat 4.8.5-14)]
CONFIGURATION
$ ansible-config dump --only-changed
DEFAULT_HOST_LIST(/opt/rhel-ansible/ansible.cfg) = [u'/opt/rhel-ansible/inventory/dev/hosts.base']
DEFAULT_ROLES_PATH(/opt/rhel-ansible/ansible.cfg) = [u'/opt/rhel-ansible/roles']
OS / ENVIRONMENT

RHEL 7.4

SUMMARY

Currently it is not possible to use vars_files to import variables when using import_playbook. It would be useful for my use case to be able to do this, as I am combining a third-party playbook with a custom inventory file, where the custom inventory file contains placeholders for common variables.

I can use vars with import_playbook, but this means that I cannot leverage my existing common variables and would need to duplicate them.

STEPS TO REPRODUCE
$ cat inventory/common_variables.yml
... snip ...
env_http_proxy: 'http://proxy.example.org'
... snip ...

$ cat playbooks/openshift/deploy-cluster.yml
---
- import_playbook: ../third-party/openshift-ansible/playbooks/byo/config.yml
  vars_files:
   - ../../inventory/common_variables.yml

$ cat inventory/dev/hosts.openshift
... snip ...
openshift_http_proxy={{ env_http_proxy }}
... snip ...
EXPECTED RESULTS

I would expect that the above should be possible.

ACTUAL RESULTS
$ sudo ansible-playbook playbooks/openshift/deploy-cluster.yml -i inventory/dev/hosts.openshift
[sudo] password for jsalmon:
ERROR! 'vars_files' is not a valid attribute for a PlaybookInclude

The error appears to have been in '/opt/rhel-ansible/playbooks/openshift/deploy-cluster.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- import_playbook: ../third-party/openshift-ansible/playbooks/byo/config.yml
  ^ here
@ansibot
Copy link
Contributor

ansibot commented Feb 28, 2018

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

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 feature_idea 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 Feb 28, 2018
@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Feb 28, 2018
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_idea labels Mar 2, 2018
@bcoca bcoca added this to Pending in include and import issues Apr 17, 2018
@bcoca bcoca moved this from Pending to Features in include and import issues Apr 17, 2018
@sivel sivel removed this from Features in include and import issues Oct 30, 2018
@ansibot ansibot added the utilities Utilities category label Feb 17, 2019
@naphta
Copy link
Contributor

naphta commented Aug 9, 2019

Any update on this issue? Is there something core blocking the implementation of this feature?

I'm happy to have a look at implementing it if there's nothing specific holding it back which I'm unaware of.

@stawii
Copy link
Contributor

stawii commented Aug 29, 2019

I would love to see this also in include_role and maybe for all other tasks/actions.
I don't see a reason why is this feature is limited only for plays.
There are many vars that are global enough to pass them here and there without need to copy-paste, but not so generic to put them inside inventory itself or extra_vars.

@ansibot
Copy link
Contributor

ansibot commented May 16, 2020

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.

click here for bot help

@Ramblurr
Copy link

There definitely seems to be an inconsistency that vars is allowed but not vars_files

@NonLogicalDev
Copy link

NonLogicalDev commented Jan 22, 2021

I would also second this, I feel like import_roles/playbooks/tasks allowing vars_files would make a huge quality of life improvement, as they will allow users to treat import_* as sort of function like blocks.

For example, you could then easily do: (somewhat contrived example)

- name: Setup telegraf service
   import_role: name="example/telegraf"
   vars_files:
     - vars/telegraf.yml
- name: Setup telegraf auxillary service
  import_role: name="example/telegraf"
  vars_files:
    - vars/telegraf-aux.yml

At the moment the closest you can come to that simplicity is (if you want the tags to work correctly)

- name: TELEGRAF | Install and Configure Telegraf
  tags: [ telegraf, sometag ]
  block:
    - include_vars: telegraf.yml
    - include_role: 
        name: "example/telegraf"
        apply:
          tags: [ telegraf, sometag ]

@sivel
Copy link
Member

sivel commented Jan 22, 2021

It's not strictly required, but the work I am doing in #73309 would make this much easier to deal with. I wouldn't work on adding vars_files until that PR merges, or we determine that #73309 is not feasible.

@ansibot ansibot added the has_pr This issue has an associated PR. label Nov 26, 2021
@mattclay mattclay added the waiting_on_contributor This would be accepted but there are no plans to actively work on it. label Jul 13, 2022
@ansibot ansibot added bot_closed and removed waiting_on_contributor This would be accepted but there are no plans to actively work on it. labels Jul 18, 2023
@ansibot
Copy link
Contributor

ansibot commented Jul 18, 2023

Thank you very much for your submission to Ansible. It means a lot to us that you've taken time to contribute.

Unfortunately, this issue has been open for some time while waiting for a contributor to take it up but there does not seem to have been anyone that did so. So we are going to close this issue to clear up the queues and make it easier for contributors to browse possible implementation targets.

However, we're absolutely always up for discussion. Because this project is very active, we're unlikely to see comments made on closed tickets and we lock them after some time. If you or anyone else has any further questions, please let us know by using any of the communication methods listed in the page below:

In the future, sometimes starting a discussion on the development list prior to proposing or implementing a feature can make getting things included a little easier, but it's not always necessary.

Thank you once again for this and your interest in Ansible!

click here for bot help

@ansibot ansibot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2023
@ansible ansible locked and limited conversation to collaborators Jul 25, 2023
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 bot_closed feature This issue/PR relates to a feature request. has_pr This issue has an associated PR. module This issue/PR relates to a module. 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

9 participants