-
Notifications
You must be signed in to change notification settings - Fork 198
Idempotency when changing sshd ports #299
Comments
Hey @nununo, thanks for raising this issue. While I personally don't change the ssh port, I can relate to this. However looking at the code in the linked article, I'm not really open to add this much code for such a "minor" issue with idempotency. |
HI @rndmh3ro, I can totally understand why you wouldn't want to add all that code. It's a bit of a mess. What you propose makes sense. If you agree, the solution to be proposed in the readme could be comprised of 2 parts:
It shoud probably also explain that fact gathering must be explicitly disabled (and manually invoked after the port was changed and Thanks! |
Sounds great! Do you want to open a PR for this? |
Sure. Give me some days to try to come up with something. I warn you though that I'm an Ansible noob so, while I'll do my best, please take that into consideration and be critical about whatever I propose :) |
Hi @rndmh3ro, I forked the rep and tried to create something as seamless as possible. While I managed to greatly simplify the example mentioned above, it still has many moving parts. Have a look at it in the
So, yeah, overall it does add a lot of complexity! Which is want you didn't want. Even I am not thrilled about it :-) But, alas, I wasn't able to make it simpler. So please be assured that I'm not trying to convince you to incorporate it :) This being a very important feature to me (idempotency is not a "minor" issue to me) I'll probably just make a new role wrapped around yours. This will give me the best of both worlds :-) Also, I don't think this can be explained in the README in a clear way. Both because this would make the README file overly complex and it would still be quite hard for someone to convert that information into something executable. But even if a solution is not proposed in the README, I still think this subject should be mentioned as it can be a source of confusion. Let me know what your thoughts are. Cheers, |
Hey @nununo, thanks for following up on this!
How about you write that wrapper-role and we put a separate section in the readme that briefly describes the problem, links to this issue here and to your wrapper role? |
Good idea. I have created a first draft here: It already works in my local environment. But it still needs some work. I want to make it more robust and user friendly. Any tips/suggestions/criticism are welcome. But what will definitely take more time is testing. I have never worked with Travis, Molecule or any of these CI testing pipelines before. So, while this is a good opportunity for me to learn how to use them, I'll first need to find the time. I'll keep you posted. |
I tested your role briefly in Centos 7 in a Docker container and it worked fine and idempotent! So I have no problem linking to it in the readme if you want to create a PR for this. |
Those are good news! I'll have to find the time to learn how to implement proper tests and then publish it in Galaxy. Once that is done I'll do the PR ;) |
Is your feature request related to a problem? Please describe.
If I want to change the default
sshd
port from22
to12345
, the server'sansible_port
should be set to12345
so that Ansible can keep connecting to the server after the change. But, since when I runssh-hardening
for the first time the port is still22
,ssh-hardening
will not be able to connect. So I am forced to edit the inventory after the first run.Describe the solution you'd like
The
ssh-hardening
rule could try to connect to both port22
and the desired final port12345
. Just like this article suggests.This way the inventory could be configured with the final port
12345
andssh-hardening
would be idempotent, work both in the first and subsequent runs.Describe alternatives you've considered
Add a custom role that runs before
ssh-hardening
implementing the solution proposed in the article linked above.Additional context
NA
The text was updated successfully, but these errors were encountered: