title: ansible - select multiple number of random names from list
body: <p>I am using ansible 2.10 and have a variable with a list of 14 names.  From this list, I want to assign a random number (from 9-14) of names and write this to a text file.  I'm struggling with how to do this in ansible. So far,  have this:</p>
  <pre><code>in default.yml:
    randomNames: 'chad', 'bob', 'alice'.....
  
   - name: Define random number
     set_fact:
       numberNames:  &quot;{{ range(9,14) }} | random }}&quot;
  
   - name: Add random names to file
     lineinfile:
       src: {{ randomNames }}
       dest: namesList.txt
     loop:
        &quot;{{ numberNames }}&quot;
  </code></pre>
  <p>but I get an error &quot;Invalid data passed to 'loop', it requires a list. I know this is isn't the correct way to do this, but can someone help me figure out what is the best way to do this?</p>
  <p>I should add I also need the names, one per line:</p>
  <pre><code>   bob
     alice
     ted
     ....
  </code></pre>