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
Conversation
There were the following issues with the commit message:
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 |
There were the following issues with the commit message:
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 |
app/models/setting/ansible.rb
Outdated
'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"'\ |
There was a problem hiding this comment.
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 "
app/models/setting/ansible.rb
Outdated
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', |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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
[test] |
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
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 I'm attaching a screenshot of the missing "Verbosity" setting. This also happened with "Private Key Path" was set to empty. |
- Realized I quoted the boolean.
# 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? |
There was a problem hiding this comment.
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?
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. |
There was a problem hiding this 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.
There was a problem hiding this 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)
There were the following issues with the commit message:
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 |
@dLobatog Thanks! I merged the changes in and recommitted. |
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 |
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.