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

fixes #20407 - adds two new options #94

Merged
merged 11 commits into from Aug 1, 2017
Merged

Conversation

mriedel-pgdx
Copy link
Contributor

@mriedel-pgdx mriedel-pgdx commented Jul 25, 2017

Fixes #20407 - adds two new options.
Adds ability to configure ansible_become & ansible_ssh_private_key_file options to foreman_ansible plugin. IDE also edited whitespace in ansible.rb file.

@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • c88ad5b must be in the format fixes #redmine_number - brief description

If you don't have a ticket number, please create an issue in Redmine.

More guidelines are available in Coding Standards or on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • length of the first commit message line for 83d1b19 exceeds 65 characters

If you don't have a ticket number, please create an issue in Redmine.

More guidelines are available in Coding Standards or on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

'ansible_ssh_private_key_file',
N_('Use this to supply a path to an SSH Private Key '\
'that Ansible will use in lieu of a password '\
'Override with "ansible_ssh_private_key_file"'\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: needs a space after the closing "

N_('Foreman will use the sudo command to run roles on hosts '\
'You can override this on hosts by adding a parameter '\
'"ansible_become"'),
'True',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try replacing 'True' with true, our helper should recognize the boolean and use dropdropdown instead of text field

# Check if private_key is defined, if it is use that. Otherwise
# use ssh_pass
if !host.host_params['ansible_ssh_private_key_file'].empty? ||
!Setting[:private_key].empty?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be Setting[:ansible_ssh_private_key_file]. Note that condition will be true out of the box since you set the default value to /tmp/private_key_file, so I would recommend keeping it blank. You can also take advantage of your host_private_key_file method and change it to:

unless host_private_key_file(host).empty?
# ...
else
# ...
end

@xprazak2
Copy link
Contributor

[test]

@xprazak2
Copy link
Contributor

Thank you for your patch, I left a few comments inline, but it looks very nice!

 - Fixes formatting
 - Fixes errant use of 'private_key' dictionary key
 - Changes boolean to 'true'
 - Removes default value for key path
@mriedel-pgdx
Copy link
Contributor Author

mriedel-pgdx commented Jul 27, 2017

Hi @xprazak2 ! Thanks for the feedback, and catching the 'private_key' I missed!

I've made the changes you suggested, except the "unless" because I'm using an "else" with it. My IDE raised a warning on that, and evidently there's some controversy over doing things that way.

Also, maybe this is a Foreman bug, but in my testing empty strings ('') as defaults caused the setting to disappear from the Ansible settings page in Foreman. The existing Default verbosity level setting does not appear in Foreman 1.15.2, and the same thing happened with ansible_ssh_private_key_file. Regardless, I've updated that too.

I'm attaching a screenshot of the missing "Verbosity" setting. This also happened with "Private Key Path" was set to empty.
screen shot 2017-07-27 at 8 38 48 am

# Check if private_key is defined, if it is use that. Otherwise
# use ssh_pass
if !host.host_params['ansible_ssh_private_key_file'].empty? ||
Setting[:ansible_ssh_private_key_file].empty?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the ! got lost, it was here before. You can keep if, I do not mind either way. My main point was that you can re-use the logic from host_private_key_file method and be more DRY:

if !host_private_key_file(host).empty?

@xprazak2
Copy link
Contributor

I solved the missing setting mystery. We have to add a setting with a blank default into whitelist. If you add:

Setting::BLANK_ATTRS.push('ansible_ssh_private_key_file')

the setting will turn up. Here is an example how we use it in other places.

Copy link
Member

@dLobatog dLobatog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the patch @mriedel-pgdx and @xprazak2 for the review. I'm cooking up something to follow this one up so that any ansible_ parameter gets converted into an option so that we don't need to add these kind of options anymore. #95

After that's done and this one is merged I think it's time for a release 😉

 - Taking educated guess on where to put the BLANK_ATTRS push
 - Using 'host_private_key_file' check in an DRY attempt.
Copy link
Member

@dLobatog dLobatog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mriedel-pgdx Sorry, this requires rebasing now. Basically you should feel free to remove the host_become and host_private_key_file methods and add these settings to the ansible_settings method. I'll merge after that if tests pass. Thanks!

 - Removes host_become & host_private_key_file
 - Left settings in Ansible Settings module
 - Reverted ansible_ssh_pass to default parameter (as it was
   prior to pull request)
@theforeman-bot
Copy link
Member

There were the following issues with the commit message:

  • f1b0c3e must be in the format fixes #redmine_number - brief description

If you don't have a ticket number, please create an issue in Redmine.

More guidelines are available in Coding Standards or on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

@mriedel-pgdx
Copy link
Contributor Author

@dLobatog Thanks! I merged the changes in and recommitted.

@dLobatog dLobatog merged commit e60bf28 into theforeman:master Aug 1, 2017
@dLobatog
Copy link
Member

dLobatog commented Aug 1, 2017

Thanks @mriedel-pgdx! Note you can use any arbitrary ansible CLI option using the latest Foreman Ansible version (only available in git now, I will release a package next week probably).

Basically any ansible_ param will be passed on to the playbook so it can be used as a connection option, similar to what you did here, except other parameters won't have a global setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants