[ansible-project] How to Random Roles

19 views
Skip to first unread message

Francis Santos

unread,
Jan 3, 2019, 8:09:40 AM1/3/19
to Ansible Project
I gotta random both the hosts and the roles.
I successfully randomed the hosts, but I not getting the roles to random.
Here is what I got

---
- hosts: "{{ (groups['foo'] | shuffle)[0:1] }}"
  become: yes
  vars:
   - ansible_sudo_pass: ******
  roles: 
   - reboot || shutdown 

Need a way to random a single role among all roles. In this example I have a reboot and shutdown

Any suggestions?

Karl Auer

unread,
Jan 3, 2019, 8:21:17 AM1/3/19
to ansible-project
Are you trying to randomly select a role, randomly select a host, then run the selected role on the selected host?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6f35d604-d0bc-4b51-9e60-7d002064256a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Karl Auer

Email  : ka...@2pisoftware.com
Website: http://2pisoftware.com


GPG/PGP : 958A 2647 6C44 D376 3D63 86A5 FFB2 20BC 0257 5816
Previous: F0AB 6C70 A49D 1927 6E05 81E7 AD95 268F 2AB6 40EA

Francis Santos

unread,
Jan 3, 2019, 10:21:49 AM1/3/19
to Ansible Project
No, the picture is that the role is not on the hosts.
First I random a host (that script does that).
Once a host is selected then the role is randomized.

Francis Santos

unread,
Jan 3, 2019, 12:41:54 PM1/3/19
to Ansible Project
I figured out.

I came with this:

- hosts: "{{ (groups['foo'] | shuffle)[0:1] }}"  #THIS SCRIPT RANDOMS THE HOST
  become: true
  vars:
   - ansible_sudo_pass: *******
  roles:
   - role: "{{ ['reboot','shutdown'] | random }}"   #THIS SCRIPT RANDOMS THE ROLE

So I guess we can consider this issue solved.

Thanks anyways, guys


On Thursday, January 3, 2019 at 11:09:40 AM UTC-2, Francis Santos wrote:
Reply all
Reply to author
Forward
0 new messages