Hi All,
I would like to execute some rules more than one time at the playbook, i tried to use;
with_sequence: count=2
but
ERROR: with_sequence is not a legal parameter in an Ansible Playbook
I would like to do something like that;
…
roles:
role1
role2
with_sequence: count={{count}}
role3
I can not decribe with_sequence inside the roles because it has lots of task.
“you cannot execute a role conditionally, you CAN pass a condition to every task in a role.”
True!
{ role: asdf, when: foo == ‘asdf’ }
Another good trick is group_by is a great way to create a small group of hosts where a given condition is true or false, and then you just apply that role to that group.
name: do something1
module: parameters
with_sequence: start=0 end={{count}}
name: do something2
module: parameters
with_sequence: start=0 end={{count}}
name: do something3
module: parameters
with_sequence: start=0 end={{count}}
name: do something4
module: parameters
with_sequence: start=0 end={{count}}
name: do something5
module: parameters
with_sequence: start=0 end={{count}}
and i don’t want to do that, because it’s not a clever way to iterate something.
It should be that difficult to iterate a role, that’s my point.
Thank you for suggestions.
Right, role iteration just can’t happen, because what happens is people will want different values to iterate for different hosts, and the way Ansible is built all task definitions in a play go to all hosts, and then those hosts evaluate conditionals.
What you ask would involve auto-converting some loops to item loops, and some item loops to nested loops, which is difficult to do in an automagical way that is intuitive.
As such, this is just somewhat hard to make a thing. If we made this a thing, ansible output wouldn’t make sense as it tries to aggregrate things for multiple hosts.