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 }}"

I get the below error when i run the playbook:


ok: [10.9.9.11] => {
> "backup": "", 
> "changed": false, 
> "diff": [
> {
> "after": "", 
> "after_header": "/tmp/httpd.conf (content)", 
> "before": "", 
> "before_header": "/tmp/httpd.conf (content)"
> }, 
> {
> "after_header": "/tmp/httpd.conf (file attributes)", 
> "before_header": "/tmp/httpd.conf (file attributes)"
> }
> ], 
> "found": 1, 
> "invocation": {
> "module_args": {
> "attributes": null, 
> "backrefs": false, 
> "backup": false, 
> "content": null, 
> "create": false, 
> "delimiter": null, 
> "directory_mode": null, 
> "firstmatch": false, 
> "follow": false, 
> "force": null, 
> "group": null, 
> "insertafter": null, 
> "insertbefore": null, 
> "line": null, 
> "mode": null, 
> "owner": null, 
> "path": "/tmp/httpd.conf", 
> "regexp": "\\sSSLFile.*", 
> "remote_src": null, 
> "selevel": null, 
> "serole": null, 
> "setype": null, 
> "seuser": null, 
> "src": null, 
> "state": "absent", 
> "unsafe_writes": null, 
> "validate": null
> }
> }, 
> "msg": "1 line(s) removed"
> } TASK [debug] 
> *******************************************************************
>
> *task path: /app/test.yml:924*ok: [10.9.9.11] => {
> "msg": {
> "backup": "", 
> "changed": false, 
> "diff": [
> {
> "after": "", 
> "after_header": "/tmp/httpd.conf (content)", 
> "before": "", 
> "before_header": "/tmp/httpd.conf (content)"
> }, 
> {
> "after_header": "/tmp/httpd.conf (file attributes)", 
> "before_header": "/tmp/httpd.conf (file attributes)"
> }
> ], 
> "failed": false, 
> "found": 1, 
> "msg": "1 line(s) removed"
> }
> } TASK [debug] 
> *******************************************************************
>
> *task path: /app/test.yml:928*fatal: [10.9.9.11]: FAILED! => {
> "msg": "'dict object' has no attribute '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.

-- 
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/47deda2a-1a8c-4387-9a5b-d2ea548ad752%40googlegroups.com.

Reply via email to