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

Include vars updated to work with directories #17207

Merged
merged 3 commits into from
Aug 30, 2016

Conversation

linuxdynasty
Copy link
Contributor

@linuxdynasty linuxdynasty commented Aug 24, 2016

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

include_vars_dir

ANSIBLE VERSION
ansible 2.1.1.0
SUMMARY

include_vars.py now allows you to include an entire directory and its nested directories of variable files. Created this PR in favor of #17195

Features..

  • Ignore any list of files.
  • Only include files nested by depth (default=unlimited)
  • Match only files matching (valid regex)
  • Sort files alphabetically and load in that order.
  • Sort directories alphabetically and load in that order.
    - include_vars: 'vars/all.yml'

    - name: include all.yml
       include_vars:
          file: 'vars/all.yml'

    - name: include all yml files in vars/all and all nested directories
      include_vars:
        dir: 'vars/all'

    - name: include all yml files in vars/all and all nested directories and save the output in test.
      include_vars:
        dir: 'vars/all'
        name: test

    - name: include all yml files in vars/services
      include_vars:
        dir: 'vars/services'
        depth: 1

    - name: include only bastion.yml files
      include_vars_dir:
        dir: 'vars'
        files_matching: 'bastion.yml'

    - name: include only all yml files exception bastion.yml
      include_vars:
        dir: 'vars'
        ignore_files: 'bastion.yml'

This change is Reviewable

@linuxdynasty
Copy link
Contributor Author

Builds are failing not cause of this module ERROR! Unexpected Exception: The 'pycrypto>=2.6' distribution was not found and is required by ansible

include_vars.py now allows you to include an entire directory and its nested directories of variable files.

Added Features..

* Ignore by default *.md, *.py, and *.pyc
* Ignore any list of files.
* Only include files nested by depth (default=unlimited)
* Match only files matching (valid regex)
* Sort files alphabetically and load in that order.
* Sort directories alphabetically and load in that order.

```
    - include_vars: 'vars/all.yml'

    - name: include all.yml
      include_vars:
        file: 'vars/all.yml'

    - name: include all yml files in vars/all and all nested directories
      include_vars:
        dir: 'vars/all'

    - name: include all yml files in vars/all and all nested directories and save the output in test.
      include_vars:
        dir: 'vars/all'
        name: test

    - name: include all yml files in vars/services
      include_vars:
        dir: 'vars/services'
        depth: 1

    - name: include only bastion.yml files
      include_vars:
        dir: 'vars'
        files_matching: 'bastion.yml'

    - name: include only all yml files exception bastion.yml
      include_vars:
        dir: 'vars'
        ignore_files: 'bastion.yml'
```
@linuxdynasty
Copy link
Contributor Author

@nitzmahone Can you check on the build when you have a moment please. @jimi-c I made the changes we discussed on irc. I added the whitelist for (json, yml, and yaml). I kept the ignore_list as a parameter and not as a default that is extended, which I am using currently. I also removed the unit tests in favor of integration tests.

@nitzmahone
Copy link
Member

@linuxdynasty Yeah, cryptography did a release this weekend that broke all our remote tests- I stuffed a fix in this afternoon and re-queued your PR build.

@abadger abadger merged commit 0313204 into ansible:devel Aug 30, 2016
@abadger
Copy link
Contributor

abadger commented Aug 30, 2016

Discussed at today's meeting. Merged! Thanks @linuxdynasty for working on this and keeping on top of us to get it reviewed and merged!

@linuxdynasty
Copy link
Contributor Author

Np and thank you guys for all the hard work you guys have done to build a product like Ansible.

@linuxdynasty
Copy link
Contributor Author

@abadger this is the PR for the updated documentation ansible/ansible-modules-core#4609

guits added a commit to guits/ceph-ansible that referenced this pull request Nov 23, 2016
As introduced in the following PR:
- ansible/ansible#17207
we need to refactor our code.
guits added a commit to guits/ceph-ansible that referenced this pull request Nov 23, 2016
As introduced in the following PR:
- ansible/ansible#17207
we need to refactor our code.
guits added a commit to guits/ceph-ansible that referenced this pull request Nov 24, 2016
As introduced in the following PR:
- ansible/ansible#17207
we need to refactor our code.
guits added a commit to guits/ceph-ansible that referenced this pull request Nov 24, 2016
As introduced in the following PR:
- ansible/ansible#17207
we need to refactor our code.
guits added a commit to guits/ceph-ansible that referenced this pull request Nov 24, 2016
As introduced in the following PR:
- ansible/ansible#17207
we need to refactor our code.
sereinity pushed a commit to sereinity-forks/ansible that referenced this pull request Jan 25, 2017
* New features for include_vars

include_vars.py now allows you to include an entire directory and its nested directories of variable files.

Added Features..

* Ignore by default *.md, *.py, and *.pyc
* Ignore any list of files.
* Only include files nested by depth (default=unlimited)
* Match only files matching (valid regex)
* Sort files alphabetically and load in that order.
* Sort directories alphabetically and load in that order.

```
    - include_vars: 'vars/all.yml'

    - name: include all.yml
      include_vars:
        file: 'vars/all.yml'

    - name: include all yml files in vars/all and all nested directories
      include_vars:
        dir: 'vars/all'

    - name: include all yml files in vars/all and all nested directories and save the output in test.
      include_vars:
        dir: 'vars/all'
        name: test

    - name: include all yml files in vars/services
      include_vars:
        dir: 'vars/services'
        depth: 1

    - name: include only bastion.yml files
      include_vars:
        dir: 'vars'
        files_matching: 'bastion.yml'

    - name: include only all yml files exception bastion.yml
      include_vars:
        dir: 'vars'
        ignore_files: 'bastion.yml'
```

* Added whitelist for file extensisions (yaml, yml, json)

* Removed unit tests in favor of integration tests
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_pull_request labels Mar 4, 2018
@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
feature This issue/PR relates to a feature request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants