Skip to content

Test idempotency and set min_ansible_version to 2.4 #50

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

Merged
merged 6 commits into from
Apr 17, 2019

Conversation

martbhell
Copy link
Contributor

@martbhell martbhell commented Apr 11, 2019

For reviewer: Feel free to squash merge and use the below as the squashed commit message:

After #49 was fixed idempotency test fails so yay it hasn't been working for a long time :)

Before this PR it was failing because the "usermod" way of modifying logged in users changes things.
That could perhaps also be improved, but with this PR now while we do the idempotency testing we do so without any logged in users.

As part of testing we now run ansible-playbook three times with two different playbooks:

  1. test.yml (which adds some users, starts a screen session as a user and then import_playbook (reason for ansible 2.4) test_idempotency.yml)
  2. test_idempotency.yml (so we can see if there is anything that changes)
  3. test_idempotency.yml and fail if grep does not find "changed=0"

Maybe running it three times would make testing miss some idempotency failures on the 3rd run, but I'm hoping not :)

test_playbook now:
 1 - run test.yml
 2 - run test.yml again
 3 - run test_idempotency.yml and fail if grep for changed=0.* does not
match
Because in travis testing I'd like to use import_playbook rather than
duplicating tests for idempotency.

It currently passes with 2.2

ansible stable-2.4 branch last real update was in September 2018
ansible stable-2.2 branch last real update was around July 2017
Copy link
Contributor

@oscarkraemer oscarkraemer left a comment

Choose a reason for hiding this comment

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

Only a question, other than that it looks good.


roles:
- ansible-role-users
post_tasks:
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll take this learning opportunity. I don't understand why this post_task is needed. What would happen if it was removed? Could it have another name or comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it's removed then ansible I think will complain about syntax errors because the task to kill the screen is not in a list of tasks.
It could be changed to tasks (or pre_tasks).
I don't know which comment you refer to so can't comment on that ;))

Copy link
Contributor

Choose a reason for hiding this comment

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

What I meant to ask was: Why do we need to kill all the screen sessions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah. If we don't then there's a 'user logged in', and the role runs the usermod way of changing said user ; which always(as per the task config) results in a run that has changed something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which brings the next good question: why do those tasks change needlessly? :)

One possible improvement to this role would be to add more conditionals to only change/run the task 1 if the GID/UID of the user (and of the logged in process or is that overkill?) are different than what is in code. If the usermod command has some nice return codes one could use those but after some searching, I couldn't find any good ones 2

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I think I remember hearing about this before. I think I now understand everything ™... ...merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👌 I created #51

@oscarkraemer oscarkraemer merged commit cb2f64f into master Apr 17, 2019
@oscarkraemer oscarkraemer deleted the test_idempotency branch April 17, 2019 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants