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

@gtmanfred
Copy link
Contributor

@gtmanfred gtmanfred 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

Copy link
Collaborator

@terminalmage terminalmage 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'])):
Copy link
Collaborator

@terminalmage terminalmage Jun 21, 2018

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

Copy link
Contributor Author

@gtmanfred gtmanfred Jun 21, 2018

cool

@gtmanfred
Copy link
Contributor Author

@gtmanfred gtmanfred commented Jun 21, 2018

Still need to write tests for this.

Copy link
Contributor

@isbm isbm 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:
Copy link
Contributor

@isbm isbm Jun 21, 2018

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)))
Copy link
Contributor

@isbm isbm Jun 21, 2018

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

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

@gtmanfred gtmanfred commented Jun 21, 2018

Test added

@gtmanfred
Copy link
Contributor Author

@gtmanfred gtmanfred commented Jun 22, 2018

re-run py

Copy link
Contributor

@isbm isbm left a comment

Cool, thanks! Some last little nitpicks though.

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

@isbm isbm Jun 22, 2018

If gitrepo is an empty string this will fail.

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

@isbm isbm Jun 22, 2018

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 = {}

Copy link
Contributor Author

@gtmanfred gtmanfred Jun 22, 2018

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

@rallytime
Copy link
Contributor

@rallytime rallytime commented Jun 22, 2018

@gtmanfred
Copy link
Contributor Author

@gtmanfred gtmanfred 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
Copy link
Collaborator

@terminalmage terminalmage 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.

Copy link
Contributor

@isbm isbm 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

@isbm isbm left a comment

LOL 😆 👍 good to go.

@rallytime rallytime requested a review from terminalmage Jun 25, 2018
@rallytime
Copy link
Contributor

@rallytime rallytime commented Jun 25, 2018

@gtmanfred Lint :)

Copy link
Contributor

@isbm isbm left a comment

@gtmanfred docs, tests. :)

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

@isbm isbm Jun 26, 2018

Docs :)

Copy link
Contributor Author

@gtmanfred gtmanfred Jun 26, 2018

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',
Copy link
Contributor

@isbm isbm Jun 26, 2018

Tests. :)

isbm
isbm approved these changes Jun 28, 2018
Copy link
Contributor

@isbm isbm left a comment

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

@rallytime
Copy link
Contributor

@rallytime rallytime commented Jun 28, 2018

@gtmanfred
Copy link
Contributor Author

@gtmanfred gtmanfred commented Jun 30, 2018

re-run py

@gtmanfred
Copy link
Contributor Author

@gtmanfred gtmanfred commented Jul 3, 2018

One last test to fix. Working on it this morning

@gtmanfred
Copy link
Contributor Author

@gtmanfred gtmanfred commented Jul 5, 2018

Ok, this should be ready.

@rallytime
Copy link
Contributor

@rallytime rallytime commented Jul 5, 2018

@gtmanfred
Copy link
Contributor Author

@gtmanfred gtmanfred commented Jul 5, 2018

re-run py

@gtmanfred
Copy link
Contributor Author

@gtmanfred gtmanfred commented Jul 6, 2018

re-run all

@rallytime
Copy link
Contributor

@rallytime rallytime commented Jul 6, 2018

re-run py

@rallytime
Copy link
Contributor

@rallytime rallytime 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/

@rallytime rallytime merged commit 490d7fb into saltstack:develop Jul 13, 2018
8 of 17 checks passed
@gtmanfred gtmanfred deleted the ansible branch Jul 13, 2018
@gtmanfred
Copy link
Contributor Author

@gtmanfred gtmanfred commented Jul 13, 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