Re: [ansible-project] Retrieving items from a dictionary

2023-09-28 Thread harry devine
Thank you Vladimir!  I had already gotten the selectattr piece working but
the length check was the missing piece.  All good now.

Thanks,
Harry

On Wed, Sep 27, 2023, 3:32 PM Vladimir Botka  wrote:

> Map the attribute
>
>   dn: "{{ ansible_mounts|
>   selectattr('device', 'contains', 'nas-server.example.com')|
>   map(attribute='device') }}"
>
> If you want to skip empty lists test the length
>
>   - debug:
>   var: dn
> when: dn|length > 0
>
> --
> Vladimir Botka
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CALYKJ26GFhRywku%3DSCMnsPsJ%2BifP888zPGHBQYv7AEwGxEQdwQ%40mail.gmail.com.


Re: [ansible-project] Retrieving items from a dictionary

2023-09-27 Thread Vladimir Botka
Map the attribute

  dn: "{{ ansible_mounts|
  selectattr('device', 'contains', 'nas-server.example.com')|
  map(attribute='device') }}"

If you want to skip empty lists test the length

  - debug:
  var: dn
when: dn|length > 0

-- 
Vladimir Botka

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20230927213245.3f39b2f8%40gmail.com.


pgpHL7pnDuN1i.pgp
Description: OpenPGP digital signature


[ansible-project] Retrieving items from a dictionary

2023-09-27 Thread lift...@gmail.com
I am trying to look at our server  mounts and only show those that have a 
specific mount available.  The playbook is as follows:

---
- hosts: all_hosts
  become: true
  become_method: sudo
  gather_facts: true

  tasks:


  - name: Get mount points
ansible.builtin.set_fact:
  device_names: "{{ ansible_mounts | selectattr('device', 'contains', 
'nas-server.example.com') | list }}"

  - name: List servers with those mount points
ansible.builtin.debug:
  msg: "{{ device_names }}"

I have 2 small issues with the output:
1) The device_names shows everything about that mount and I only want to 
show the device attribute;
2) Hosts that do not have the mount present show up in my debug list with 
an empty string.  I'd like to not show them at all if possible.

ok: [server1.example.com] => {
"msg": [
{
"block_available": 26201799211,
"block_size": 4096,
"block_total": 36234081792,
"block_used": 10032282581,
"device": "nas-server.example.com:/projects",
"fstype": "fuse.glusterfs",
"inode_available": 14493376449,
"inode_total": 14495510592,
"inode_used": 2134143,
"mount": "/projects",
"options": 
"rw,nodev,relatime,user_id=0,group_id=0,allow_other,max_read=131072",
"size_available": 107322569568256,
"size_total": 148414799020032,
"uuid": "N/A"
}
]
}
ok: [server2.example.com] => {
"msg": []
}

Thanks for any help,
Harry

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/b724b0c0-93e7-4516-b839-73dd7141cb94n%40googlegroups.com.