Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Replace equalto as it is support since jinja 2.10
Browse files Browse the repository at this point in the history
This patch replace selectattr('x', 'equalto', 'y'), by custom filter as
'equalto' is supported since jinja 2.10.

Change-Id: If4062497278e05b114ce86b3e43ef507d8a84173
Signed-off-by: Ondra Machacek <omachace@redhat.com>
  • Loading branch information
machacekondra committed Aug 30, 2018
1 parent 761b621 commit 0519550
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions filter_plugins/ovirtvmip.py
Expand Up @@ -11,8 +11,17 @@ def filters(self):
'ovirtvmipsv4': self.ovirtvmipsv4,
'ovirtvmipv6': self.ovirtvmipv6,
'ovirtvmipsv6': self.ovirtvmipsv6,
'filtervalue': self.filtervalue,
}

def filtervalue(self, data, attr, value):
""" Filter to findall occurance of some value in dict """
items = []
for item in data:
if item[attr] == value:
items.append(item)
return items

def ovirtvmip(self, ovirt_vms, attr=None):
'Return first IP'
return self.__get_first_ip(self.ovirtvmips(ovirt_vms, attr))
Expand Down
4 changes: 2 additions & 2 deletions tasks/create_inventory.yml
Expand Up @@ -15,7 +15,7 @@
ansible_host: "{{ item | ovirtvmipv4 }}"
groups: "{{ (['ovirt_tag_'] * item.tags | length) | zip(item.tags | map(attribute='name') | list) | map('join') | list + ['ovirt_vm'] }}"
ansible_user: root
ansible_password: "{{ vms_passwords | selectattr('name', 'equalto', item.name) | map(attribute='root_password') | first | default(omit) }}"
ansible_password: "{{ vms_passwords | filtervalue('name', item.name) | map(attribute='root_password') | first | default(omit) }}"
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
with_items: "{{ ovirt_vms }}"
changed_when: false
Expand All @@ -30,7 +30,7 @@
ansible_host: "{{ item | ovirtvmipv6 }}"
groups: "{{ (['ovirt_tag_'] * item.tags | length) | zip(item.tags | map(attribute='name') | list) | map('join') | list + ['ovirt_vm'] }}"
ansible_user: root
ansible_password: "{{ vms_passwords | selectattr('name', 'equalto', item.name) | map(attribute='root_password') | first | default(omit) }}"
ansible_password: "{{ vms_passwords | filtervalue('name', item.name) | map(attribute='root_password') | first | default(omit) }}"
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
with_items: "{{ ovirt_vms }}"
changed_when: false
Expand Down

0 comments on commit 0519550

Please sign in to comment.