-
Notifications
You must be signed in to change notification settings - Fork 134
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 un-overrideable public api variables #199
Conversation
I cannot fix the failing ansible-lint test. The master branch has the same error, so I guess this PR is ready to review. |
This breaks some integration tests - the handler that starts/restarts sshd fails because
This is because the test resets
This is because https://github.com/willshersystems/ansible-sshd/pull/199/files#diff-3ca6b148feb962b6f4e0c2a016f5f5f22d3b881aa387a29ef466be43fdd537f5R2
|
These are fixed by #198 already (known ansible(-lint) bug if I see right). |
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.
Can you provide a some examples of a playbook that did not work for you, ideally as part of test case here, which could be used as a regression test to make sure this keeps working in the future?
How can I run these tests? |
I'm not sure what the ansible-sshd authors would recommend. The linux system roles team is based on Fedora as the development platform. We use tox and tox-lsr to run the tests using qemu/kvm. https://linux-system-roles.github.io/contribute.html
With this, I can run the tests like this:
To run the test playbook |
I made some changes to address the error with the undefined name. Now, the unsetting of variables is the last thing that happens in the role. It also happens only when it is absolutely needed. I will try to come up with some test case. |
I still had some failures with 438e010 so I tried to fix it: https://github.com/richm/ansible-sshd/tree/revert-richm include_role:
name: sshd
vars:
sshd_config_file: /path/to/1
...
include_role:
name: sshd
vars:
sshd_service: my_custom_sshd_service Where the value |
The reason I reset the public API variables is because in my implementation they become facts. According to Ansible's variable precedence rules, facts take precedence over playbook vars and others. This means that sth like the below snippet will fail: - hosts: all
vars:
sshd_config_file: /custom/config1
roles:
- ansible-sshd
- hosts: all
roles:
- ansible-sshd
# user expects to run with OS default for sshd_config_file,
# but /custom/config1 is used instead. Here is where resetting
# the variables to None is useful.
- hosts: all
vars:
sshd_config_file: /custom/config2 # this has no effect
roles:
- ansible-sshd
You are right, using intermediate variables or boolean expressions is the proper solution as it would cover the third case above as well and not need unsetting the variables at all. I started with the assumption that using intermediate variables or logic expression would make the code hard to read and maintain, but not using them breaks user expectations. I will rewrite the PR using intermediate variables. |
I completely rewrote the PR. The issue was actually much simpler, some defaults (e.g. |
BTW, should |
lgtm - works locally using qemu/kvm tests - other than the ansible-lint issues, most of which are fixed by #198, I think this is good to go |
Probably yes, but I think we did not get a request for that yet. |
tests pass locally with qemu + ansible-core 2.13 + centos-9 vm |
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.
hopefully last comment regarding the test backup. The rest looks good.
I think we are good here. @mattwillsher what do you think? Ready to merge? |
I'm happy if you all are - I can follow the reasoning for the change. Please can someone produce a changelog for this please and I'll get it up to Galaxy. Slightly off-topic but I've been considering a rewrite of the module to try and consolidate the many changes that have occurred to this code base over the years. I'm getting a little concerned about general stability and side effects of changes. |
The only change since last release was the #201 fixing the auto-tag so I would wait for at least #200 to finalize before doing a new release. For a oneliner, this basically fixes #170 and similar cases, so something like
I am not sure if a module would help here much, but I dont have much practical experience with modules. For the stability and side effects of the changes, we have tests coverage, but indeed there might slip some issues such as this one. |
I mean role (too much Terraform for me these days!). Perhaps things are ok, I just need to spend more time with the code |
This reverts commit f32003f.
That commit hardcoded many variables to the values under
vars/
, making it impossible for the user to parameterize things like the systemd service name. The assumption was that the__sshd_*
variables were useless in an effort to blindly adhere to best practices, but they were crucial in allowing flexibility to the user.The way the test suite is set up is a bit strange for me, but I tried to make it pass with minimum changes.