Это может быть достигнуто с помощью фильтра когда и lower
ansible. Приведенный ниже playbook работает для меня.
Playbook:
- name: Demo of restore plan
hosts: localhost
gather_facts: False
vars:
datacenters: {
cabinets: {
servers: [
{
name: Server1,
id: 1
},
{
name: SERVER1,
id: 2
},
{
name: Server2,
id: 3
},
{
name: server1,
id: 4
},
]
}
}
tasks:
- debug:
msg: "{{ item.name }}"
with_items:
- "{{ datacenters.cabinets.servers }}"
when: item.name|lower == "server1"
Вывод:
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [Demo of restore plan] ************************************************************************************************************************************************
TASK [debug] ***************************************************************************************************************************************************************
ok: [localhost] => (item={'name': 'Server1', 'id': 1}) => {
"msg": "Server1"
}
ok: [localhost] => (item={'name': 'SERVER1', 'id': 2}) => {
"msg": "SERVER1"
}
skipping: [localhost] => (item={'name': 'Server2', 'id': 3})
ok: [localhost] => (item={'name': 'server1', 'id': 4}) => {
"msg": "server1"
}
PLAY RECAP *****************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Ansible перечисляет только строку server1 и игнорирует server2
Надеюсь, это поможет