jstar100x
jstar100x

Reputation: 47

How can I use a jq query to extract a string from this Ansible dictionary?

So I have the following tasks in my playbook

- name: gather package facts
  package_facts:

- name: send packages containing 'fence-agents' to a file
  lineinfile:
    path: /etc/leapp/transaction/to_remove
    line: "{{ item }}"
  loop: "{{ ansible_facts.packages | ???????"
  become: true 

Is there anyway to extract a list with all packages which contain the string fence-agents?

I don't want to loop the entire package list as it would increase the playbook run time significantly.

Upvotes: 0

Views: 51

Answers (1)

U880D
U880D

Reputation: 12124

Q: "Is there anyway to extract a list with all packages which contain the string fence-agents?"

An approach based on the given question example

  - debug:
      msg: "{{ ansible_facts.packages[item] }}"
    loop: "{{ ansible_facts.packages | select('search', regex) }}"
    vars:
      regex: 'fence-agents*'

Similar Q&A

Upvotes: 2

Related Questions