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

Revamp ansible roster to use ansible-inventory #48538

Merged
merged 6 commits into from Jul 16, 2018

Conversation

@gtmanfred
Copy link
Contributor

@gtmanfred gtmanfred commented Jul 11, 2018

What does this PR do?

Ansible now provides an ansible-inventory command which renders the inventory script/file. Because of this, we can now use that command to render the inventory for ourselves, instead of having to maintain code to process the file as well.

Tests written?

Yes

Commits signed with GPG?

Yes

@gtmanfred gtmanfred requested a review from as a code owner Jul 11, 2018
@ghost ghost requested review from Jul 11, 2018
if key not in self.parents:
self.parents[key] = []
self.parents[key].extend(value)
inventory = __runner__['salt.cmd']('cmd.run', 'ansible-inventory -i {0} --list'.format(get_roster_file(__opts__)))
Copy link
Contributor

@isbm isbm Jul 12, 2018

I am really wondering why we would execute that in so heavy-weight fashion spinning off another Python interpreter etc, instead of just reuse the ansible.cli.InventoryCLI for this. As a conceptual example:

try:
    import ansible.cli.inventory as ansible_inventory
except
    ansible_inventory = None

def __virtual__():
    return ansible_inventory and __virtualname__, 'Ansible is not installed on your system'

def ...:

    c = ansible_inventory.InventoryCLI(['', '-i', get_roster_file(__opts__), '--list'])
    c.parse()
    inventory = c.run()

    ...

Copy link
Contributor Author

@gtmanfred gtmanfred Jul 12, 2018

We still support python 3.4, which ansible does not, so in order to use ansible-inventory on centos 7, right now you have to pip2 install ansible, and then run the binary.

Until we drop python3.4 support i think this is the better setup.

Copy link
Contributor

@isbm isbm Jul 12, 2018

Ah, you're right. CentOS 7 and family on 3.4. OK, in this case we should do the fallback then:

return (ansible_inventory or which('ansible-inventory')) and __virtualname__, '....'

I still don't want to spin-off another Python process on an expensive IBM Mainframe, where every bit of RAM is for gold. 😉 Once we stop 3.4 support, we can just drop this part.

Copy link
Contributor Author

@gtmanfred gtmanfred Jul 12, 2018

.tox/py36/lib/python3.6/site-packages/ansible/cli/inventory.py:186: in run
    exit(0)
_ _ _ _ _ _ _ _

This is why we cannot use the ansible/cli/inventory.py script, because it calls a system exit. and just displays the results instead of returning them.

isbm
isbm approved these changes Jul 12, 2018
Copy link
Collaborator

@terminalmage terminalmage left a comment

blind-review

@rallytime rallytime merged commit bdeeed5 into saltstack:develop Jul 16, 2018
8 of 17 checks passed
8 of 17 checks passed
continuous-integration/jenkins/pr-merge This commit cannot be built
Details
jenkins/PR/salt-pr-linode-ubuntu16-py3 Pull Requests » Salt PR - Linode Ubuntu16.04 - PY3 #11431 — ABORTED
Details
default Build finished.
Details
jenkins/PR/salt-pr-linode-cent7-py3 Pull Requests » Salt PR - Linode CentOS 7 - PY3 #6461 — FAILURE
Details
jenkins/PR/salt-pr-linode-ubuntu14-n Pull Requests » Salt PR - Linode Ubuntu14.04 #24389 — FAILURE
Details
jenkins/PR/salt-pr-rs-cent7-n Pull Requests » Salt PR - RS CentOS 7 #20514 — FAILURE
Details
jenkins/pr/py3-centos-7 The py3-centos-7 job has failed
Details
jenkins/pr/py3-ubuntu-1604 The py3-ubuntu-1604 job has failed
Details
jenkins/pr/py2-centos-7 running py2-centos-7...
Details
@wip[bot]
WIP ready for review
Details
codeclimate 9 fixed issues
Details
jenkins/PR/salt-pr-clone Pull Requests » Salt PR - Clone #26677 — SUCCESS
Details
jenkins/PR/salt-pr-docs-n Pull Requests » Salt PR - Docs #18706 — SUCCESS
Details
jenkins/PR/salt-pr-lint-n Pull Requests » Salt PR - Code Lint #23343 — SUCCESS
Details
jenkins/pr/docs The docs job has passed
Details
jenkins/pr/lint The lint job has passed
Details
jenkins/pr/py2-ubuntu-1604 The py2-ubuntu-1604 job has passed
Details
@gtmanfred gtmanfred deleted the ansibleroster branch Jul 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants