Dusty
Dusty

Reputation: 129

Ansible filter stdout_lines cut or split

I have a variable which contains a few lines and I want to find of a line having this value and after split based a delimiter and take only the first value of that specific line.

Task:1
   - debug:
       var: blabla.stdout_lines

Output
  blabla.stdout_lines:
  - 1 test1 aaa
  - 2 test0 bbb
  - 3 test444 ccc


Task:2
   - name: test
     debug:
       msg: "{{ blabla.stdout | select('search', 'test1') | list }}"
Output
  msg:
  -  1 test1 aaa

I would like to have a split so it takes just the value "1" directly in the task2. I tried to do a textsplit and cut into it but seems it wasn't working. I am trying to add another Jinja filter into the Task2.

Upvotes: 1

Views: 4862

Answers (1)

Dusty
Dusty

Reputation: 129

Managed to used regex_search() as Matthew suggested

   - name: Extract valuevariables

     set_fact:

        webapps_not: "{{ blabla.stdout | regex_search('.+?(?=no)') }}"


   - name: Show value

     debug: var=blabla_not

Upvotes: 1

Related Questions