ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
93 stars 19 forks source link

Expose history of run roles as a variable #143

Closed nkakouros closed 4 years ago

nkakouros commented 5 years ago

Proposal:

Author: Nikolaos Kakouros <@tterranigma>

Date: 2018-09-20

Motivation

Now that we have import_role and include_role which can be used with conditionals, it would be nice to have a way to access the history of run roles.

Problems

What problems exist that this proposal will solve?

Solution proposal

- import_role: name=role1
  when: condition1
- import_role: name=role2
  when: condition2
- import_role: name=role3
  when:
    - condition3
    - 'role1' in ansible_executed_roles
    - 'role2' not in ansible_executed_roles
- import_role: name=role4
  when:
    - 'role3' not in ansible_executed_roles
- copy:
    content: "{{ ansible_executed_role }}"
    dest: scenario.yml
  delegate_to: localhost

This could be achieved now also by creating long when lists.

An issue might be how to do this, per playbook, per play or both.

webknjaz commented 5 years ago

cc @bcoca

bcoca commented 5 years ago

A few considerations;

sivel commented 5 years ago

Also, it should be mentioned that any use of import_role or roles specified under roles would immediately be listed as executed, as they are preprocessors that are expanded at parse time.

I'm not sure how useful of a feature this would be. I agree with @bcoca that if you need this type of functionality, using set_fact is probably the most reliable way of making this determination.

nkakouros commented 4 years ago

I don't think I have a use case for this anymore, so closing this as you have described the limited use and the difficulties with sth like that.