All,
I need some help writing the following task.
1. Need to find all devices on a RHEL system, but only if they don't match 
sr0
2. 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"*
*-------------------------------------------------------------------------------*
- name: print devices
  debug: msg="Device name is "{{ item.key }}""
  with_dict: "{{ ansible_devices }}"
  when: ansible_devices*['key'] *== "vdb"
*------------------------------------------------------------------------------*
- name: print devices
  debug: msg="Device name is "{{ item.key }}""
  with_dict: "{{ ansible_devices }}"
  when: ansible_devices* | search('vdb')*


-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/14d18be8-d1b1-4044-ba00-5ee4eada986e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to