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

ansible-test idempotence tests for roles in Ansible Collections #60226

Open
geerlingguy opened this issue Aug 7, 2019 · 3 comments

Comments

@geerlingguy
Copy link
Contributor

commented Aug 7, 2019

SUMMARY

It would be nice to be able to test role idempotence in Ansible Collections when running integration tests with ansible-test.

Currently it's easy to test the idempotence of a single task, e.g.:

- module_name:
    key: value
  register: result

- fail:
  when: result.changed

However, when testing roles (e.g. via include_role), there is no easy way to test idempotence:

- name: Run the PHP role.
  include_role:
    name: geerlingguy.php_roles.php

- name: Test the PHP role's idempotence.
  include_role:
    name: geerlingguy.php_roles.php
  register: idempotence_result

In the case of include_role, the changed status is always false because the tasks in the included role are inlined and don't affect the status of the actual act of including them...

Right now the only way to test idempotence is to write your own shell script in a runme.sh script, manually running the playbook two times, and then parsing the results using regex or string matching to check for changed=0.

I used to do that kind of thing before Molecule came along, but with Molecule, it includes easy integrated idempotence checks, where it basically re-runs the entire test playbook and checks for changes.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

ansible-test

ADDITIONAL INFORMATION

I propose a new CLI flag like --test-idempotence (or something like that), and if it is passed, it would run the integration target a 2nd time for each target, verifying the 2nd time that changes=0.

@ansibot

This comment has been minimized.

Copy link
Contributor

commented Aug 7, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@samdoran

This comment has been minimized.

Copy link
Member

commented Aug 7, 2019

I would suggest the flag be something like:
--check-end-state
--check-desired-state
--test-end-state

Just throwing out some ideas.

@mattclay

This comment has been minimized.

Copy link
Member

commented Aug 7, 2019

This is something that should be configured by the aliases file used by ansible-test, rather than a CLI option, since it's target specific. That way ansible-test will automatically know to run the test twice and check for changes.

@mattclay mattclay removed the needs_triage label Aug 7, 2019

@mattclay mattclay added this to To do in Testing Collections via automation Aug 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can’t perform that action at this time.