All,
I need some help writing the following task.
- Need to find all devices on a RHEL system, but only if they don’t match sr0
- For each of those devices found, run a number of tasks against them
Thought this would be a simple matter of accessing items in a dict or list, using when: to match the devices I’m looking for, but I’m thoroughly lost.
Here is an example of the facts I’m looking for (I removed a lot of the elements for readability, denoted by the <…> )
“ansible_devices”: {
“sr0”: {
“holders”: ,
“host”: “”,
<…>
},
“vda”: {
“holders”: ,
“host”: “”,
<…>
},
<…>
Now, here is what I want to do to each device I find that doesn’t match sr0. I’m struggling in figuring out how to set new_dev
- name: Label new disk
command: parted -s -a optimal “{{ new_dev }}” mklabel gpt
I’ve tried the following to test loops and conditionals:
- name: print devices
debug: msg=“Device name is “{{ item.key }}””
with_dict: “{{ ansible_devices }}”
Which works, but when I add any number of attempts to apply conditionals, I have failure. Here is some of what I’ve tried, with the differences highlighted.
- name: print devices
debug: msg=“Device name is “{{ item.key }}””
with_dict: “{{ ansible_devices }}”
when: ansible_devices.key == “vdb”