Regular expression and Linux command in Ansible

133 views
Skip to first unread message

Marian Saldhana

unread,
Jan 5, 2022, 10:21:27 AM1/5/22
to Ansible Project
Hi All,

I am trying to run a playbook where when I entre standard ansible modules using regular expressions it works fine ( Thanks to Todd for helping me with it), however when I entre a Linux command in place of an ansible module it does not work as expected. An suggestion or guidance to make it would be of great help to resolve my issue.
The playbook is:- ( I have highlighted the command that I wish to execute )
+++
---
- hosts: all
  gather_facts: True
  become: false
  tasks:
  - name: show file contents
    debug:
      msg: "{{ lookup('file', 'customer-expects.txt') }}"

  - name: Correct kernel?
    set_fact:
      # These dashes matter.
      expectation: |-
        {%- if lookup('file', 'customer-expects.txt')
              is regex(['shell:"cat /etc/redhat-release"']|join(' ')|regex_escape()) -%}
        matched
        {%- else -%}
        missed
        {%- endif -%}

Thanks,
Marian
Reply all
Reply to author
Forward
0 new messages