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

add ansible playbook runner to ansiblegate module #48254

Merged
merged 17 commits into from Jul 13, 2018

Conversation

Projects
None yet
4 participants
@gtmanfred
Copy link
Contributor

commented Jun 21, 2018

What does this PR do?

Adds the ability to run ansible playbooks from salt execution modules or from states, specifically for orchestration states.

Tests written?

Added

Commits signed with GPG?

Yes

@rallytime rallytime requested review from isbm and terminalmage Jun 21, 2018

@terminalmage
Copy link
Contributor

left a comment

Just one minor change I would make, otherwise this is ++.

if ansible_kwargs is None:
ansible_kwargs = {}
checks = __salt__['ansible.playbooks'](name, rundir=rundir, check=True, diff=True, **ansible_kwargs)
if all(not check['changed'] for _, check in six.iteritems(checks['stats'])):

This comment has been minimized.

Copy link
@terminalmage

terminalmage Jun 21, 2018

Contributor

You can use six.itervalues() here and not need to use the "throwaway" variable.

This comment has been minimized.

Copy link
@gtmanfred

gtmanfred Jun 21, 2018

Author Contributor

cool

@gtmanfred

This comment has been minimized.

Copy link
Contributor Author

commented Jun 21, 2018

Still need to write tests for this.

@isbm
Copy link
Contributor

left a comment

Generally, if we want to validate the params, we should do it explicitly. Otherwise I would use Pythonic checks (see the comment).

Otherwise, excellent, woohoo!! 😎

salt 'ansiblehost' ansible.playbook playbook=/srv/playbooks/play.yml
'''
command = ['ansible-playbook', playbook]
if check is True:

This comment has been minimized.

Copy link
@isbm

isbm Jun 21, 2018

Contributor

What is the reason to explicitly check the type alongside the value? I.e. why if check: is not sufficient?

if diff is True:
command.append('--diff')
if extra_vars is not None:
command.append('--extra-vars={0}'.format(json.dumps(extra_vars)))

This comment has been minimized.

Copy link
@isbm

isbm Jun 21, 2018

Contributor

Hmm, still the same question though. I'd say if extra_vars:

@gtmanfred gtmanfred force-pushed the gtmanfred:ansible branch from 71303cb to 31c6c84 Jun 21, 2018

@gtmanfred gtmanfred changed the title [WIP] add ansible playbook runner to ansiblegate module add ansible playbook runner to ansiblegate module Jun 21, 2018

@gtmanfred

This comment has been minimized.

Copy link
Contributor Author

commented Jun 21, 2018

Test added

@gtmanfred gtmanfred force-pushed the gtmanfred:ansible branch from 64bd402 to ce14410 Jun 21, 2018

@gtmanfred gtmanfred force-pushed the gtmanfred:ansible branch from ce14410 to 6ef47ae Jun 22, 2018

@gtmanfred

This comment has been minimized.

Copy link
Contributor Author

commented Jun 22, 2018

re-run py

@isbm
Copy link
Contributor

left a comment

Cool, thanks! Some last little nitpicks though.

'comment': 'Running playbook {0}'.format(name),
'name': name,
}
if gitrepo is not None:

This comment has been minimized.

Copy link
@isbm

isbm Jun 22, 2018

Contributor

If gitrepo is an empty string this will fail.

**git_kwargs,
)
if ansible_kwargs is None:
ansible_kwargs = {}

This comment has been minimized.

Copy link
@isbm

isbm Jun 22, 2018

Contributor

Maybe this is better way, unless we do not want to validate all that and crash with the error "You've passed an empty string instead of a parameters" (or something like that):

if not ansible_kwargs:
    ansible_kwargs = {}

This comment has been minimized.

Copy link
@gtmanfred

gtmanfred Jun 22, 2018

Author Contributor

I am just going to check if it a dict and if it isn't then i will set it to {}.

@rallytime

This comment has been minimized.

@gtmanfred

This comment has been minimized.

Copy link
Contributor Author

commented Jun 23, 2018

This should be all set to go on the next test run.

@gtmanfred gtmanfred requested review from terminalmage and isbm Jun 23, 2018

@terminalmage
Copy link
Contributor

left a comment

Is gitrepo part of a naming convention used elsewhere? If not, it may make sense to change it. I'm just worried about confusion between gitrepo (no underscore) and git_kwargs (underscore). It seems like this could lead to confusion/typos.

@isbm
Copy link
Contributor

left a comment

@terminalmage actually a very good catch, it slipped out of my radar: the git_<something> is better convention than git<something>.

@gtmanfred could you please appease BOFH (and terminalmage) by looking into name conventions and checking to None one more time? 😉 I would appreciate that.

Other then that, it is good to go as of my current views.

@isbm

isbm approved these changes Jun 25, 2018

Copy link
Contributor

left a comment

LOL 😆 👍 good to go.

@rallytime rallytime requested a review from terminalmage Jun 25, 2018

@rallytime

This comment has been minimized.

Copy link
Contributor

commented Jun 25, 2018

@gtmanfred Lint :)

@isbm
Copy link
Contributor

left a comment

@gtmanfred docs, tests. :)

run nginx install:
ansible.playbooks:
- name: install.yml
- gitrepo: git://github.com/gituser/playbook.git

This comment has been minimized.

Copy link
@isbm

isbm Jun 26, 2018

Contributor

Docs :)

This comment has been minimized.

Copy link
@gtmanfred

gtmanfred Jun 26, 2018

Author Contributor

bah... i did a search replace... apparently i am just terrible at regex.

ret = self.run_state(
'ansible.playbooks',
name='install.yml',
gitrepo='git://github.com/gtmanfred/playbooks.git',

This comment has been minimized.

Copy link
@isbm

isbm Jun 26, 2018

Contributor

Tests. :)

@isbm

isbm approved these changes Jun 28, 2018

Copy link
Contributor

left a comment

@gtmanfred thanks! Hopefully now it is OK to go.

@rallytime

This comment has been minimized.

Copy link
Contributor

commented Jun 28, 2018

@gtmanfred

This comment has been minimized.

Copy link
Contributor Author

commented Jun 30, 2018

re-run py

@gtmanfred gtmanfred force-pushed the gtmanfred:ansible branch from 42a2c6b to 2711b1f Jul 3, 2018

@gtmanfred

This comment has been minimized.

Copy link
Contributor Author

commented Jul 5, 2018

Ok, this should be ready.

@rallytime

This comment has been minimized.

@gtmanfred

This comment has been minimized.

Copy link
Contributor Author

commented Jul 5, 2018

re-run py

@gtmanfred

This comment has been minimized.

Copy link
Contributor Author

commented Jul 6, 2018

re-run all

@rallytime

This comment has been minimized.

Copy link
Contributor

commented Jul 6, 2018

re-run py

@rallytime

This comment has been minimized.

Copy link
Contributor

commented Jul 9, 2018

@gtmanfred I think the following test is related. I am not seeing this fail elsewhere:

  • integration.modules.test_cmdmod.CMDModuleTest.test_run

https://jenkins.saltstack.com/job/PR/job/salt-pr-linode-ubuntu16-py3/11261/

@gtmanfred gtmanfred force-pushed the gtmanfred:ansible branch from 4fe15de to fa1a1d2 Jul 10, 2018

gtmanfred added some commits Jun 21, 2018

appease BOFH
Also, handle @ for extra_vars
fix pylint
handle git_kwargs and ansible_kwargs better as well.
Load ansible.playbooks if binary is installed
Don't load extra ansible module stuff is ansible is not importable.

Use @Depends decorator https://docs.saltstack.com/en/latest/ref/modules/#depends-decorator
fix unittest
Ansiblegate should always be included now, the list and help functions
will just be removed in the loader when Depends.enforce_dependencies is
run.

@gtmanfred gtmanfred force-pushed the gtmanfred:ansible branch from fa1a1d2 to 30eafdb Jul 12, 2018

@rallytime rallytime merged commit 490d7fb into saltstack:develop Jul 13, 2018

8 of 17 checks passed

jenkins/PR/salt-pr-linode-ubuntu16-py3 Pull Requests » Salt PR - Linode Ubuntu16.04 - PY3 #11378 — ABORTED
Details
jenkins/PR/salt-pr-rs-cent7-n Pull Requests » Salt PR - RS CentOS 7 #20461 — ABORTED
Details
codeclimate 9 issues to fix
Details
default Build finished.
Details
jenkins/PR/salt-pr-linode-cent7-py3 Pull Requests » Salt PR - Linode CentOS 7 - PY3 #6408 — FAILURE
Details
jenkins/PR/salt-pr-linode-ubuntu14-n Pull Requests » Salt PR - Linode Ubuntu14.04 #24336 — FAILURE
Details
jenkins/pr/py2-centos-7 The py2-centos-7 job has failed
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
WIP ready for review
Details
continuous-integration/jenkins/pr-merge This commit looks good
Details
jenkins/PR/salt-pr-clone Pull Requests » Salt PR - Clone #26623 — SUCCESS
Details
jenkins/PR/salt-pr-docs-n Pull Requests » Salt PR - Docs #18653 — SUCCESS
Details
jenkins/PR/salt-pr-lint-n Pull Requests » Salt PR - Code Lint #23289 — 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 gtmanfred:ansible branch Jul 13, 2018

@gtmanfred

This comment has been minimized.

Copy link
Contributor Author

commented Jul 13, 2018

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.