mercredi 26 août 2020

ansible - read file, then randomly select entry

I'm using Ansible 2.9.10. I am trying to read a file in which consists of a list of items. I then want to choose 3 random items from this list. I've tried several things (noted below) but cannot seem to figure this out.

The file itemList is a list of items, one per line:

hammer
saw
wood
.....

In the playbook I have:

vars:
  file_contents: ""

# Printing file contents returns "widget\hammer\nsaw\nwood"..... etc. 
- name: Print file contents
  debug:
    msg: "File contents are "


# Now try to select one random item from file_contents
- name: Select one random item
  debug:
     msg: "item is "
  with_random_choice: ""

What am I missing? It seems as though I am making it harder than it seems. TIA




Aucun commentaire:

Enregistrer un commentaire