# How to random roles

**URL:** <https://forum.ansible.com/t/how-to-random-roles/29351>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [January 2, 2019, 1:53pm UTC](https://forum.ansible.com/t/how-to-random-roles/29351 "2019-01-02T13:53:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francis\_Santos](https://avatars.discourse-cdn.com/v4/letter/f/49beb7/32.png) [@Francis\_Santos](https://forum.ansible.com/u/Francis_Santos)\
**Post date:** [January 2, 2019, 1:53pm UTC](https://forum.ansible.com/t/how-to-random-roles/29351/1 "2019-01-02T13:53:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Francis\_Santos](https://avatars.discourse-cdn.com/v4/letter/f/49beb7/32.png) [@Francis\_Santos](https://forum.ansible.com/u/Francis_Santos)\
**Post date:** [January 3, 2019, 4:55pm UTC](https://forum.ansible.com/t/how-to-random-roles/29351/2 "2019-01-03T16:55:26Z")

</div>

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
