On 15.01.2020 06:34, Shifa Shaikh wrote:
I wish to search for all entries of string starting with "SSLFile" or
starting with "<whitespache>SSLFile" in a file(httpd.conf) and register it
to a variable and print all the matches found.
The string is found as evident from the output and the file is not modified
which is good; but I'm unable to print (debug) it. I get error as I try to
print. Below is my playbook:
- name: Find entries
lineinfile:
path: "/tmp/httpd.conf"
regexp: "\\sSSLFile.*"
state: absent
check_mode: yes
changed_when: false
register: filedet
- debug:
msg: "{{ filedet }}"
- debug:
msg: "{{ item.split()[1] }}"
with_items:
- "{{ filedet.stdout_lines }}"
Can you please suggest what is the correct way to print all the searched
matched strings without modifying the file ? I wish to use the the
registered variable to perform other actions later in the playbook.
Just use grep
- command: grep -P "^\s*SSLFILE" /tmp/httpd.conf
register: results
- debug: msg="{{ results.stdout }}"
- debug: msg="{{ item }}"
with_items: "{{ results.stdout_lines }}"
--
Kai Stian Olstad
--
You received this message because you are subscribed to the Google Groups "Ansible
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/35f8142c-79b6-9e73-4df6-cb07462af366%40olstad.com.