Skip to content

Instantly share code, notes, and snippets.

@dudebowski
Last active May 27, 2020 09:29
Show Gist options
  • Select an option

  • Save dudebowski/4372f9947018060fa6f527a7bddc096d to your computer and use it in GitHub Desktop.

Select an option

Save dudebowski/4372f9947018060fa6f527a7bddc096d to your computer and use it in GitHub Desktop.
select one item from listand put it in a fact
---
- name: select
gather_facts: false
hosts: localhost
connection: local
vars:
- my_selector:
- "the_value_to_select"
tasks:
- name: use it
debug:
msg: "{{ first_user }}"
- name: put it in a fact
set_fact:
my_fact: "{{ the_list| selectattr('attribute_name', 'match', lookup('vars', myvar) | first) | first }}"
vars:
my_var: selector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment