相关文章推荐
奔跑的煎饼果子  ·  PHP Libraries tagged ...·  1 年前    · 
乐观的生姜  ·  2. React ...·  1 年前    · 

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary

I've successfully used regex_search many times to filter stdout_lines from stored variables. Examples:

db2_sh_out_lines: "{{ (db6_update_db_result.stdout_lines | regex_search('db2 -z.+.sql') | regex_replace(\" '\\s+|'\", '')).split(',') }}"

java_inst: "{{ lssap_output.stdout_lines | regex_search('J[0-9][0-9]|$') }}"

This suddenly stopped working for me and now I can only filter stdout with regex_search. First used regex_search like this on Ansible 2.9.14.

Issue Type

Bug Report

Component Name

regex_search

Ansible Version

$ ansible --version
ansible 2.9.23
  config file = /home/saplls/git/IBM_DB2_patching/ansible.cfg
  configured module search path = [u'/home/saplls/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Aug 13 2020, 02:51:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

Configuration

$ ansible-config dump --only-changed
ALLOW_WORLD_READABLE_TMPFILES(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = True
ANSIBLE_SSH_ARGS(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = -C -o ControlMaster=auto -o ControlPersist=30m -o ServerAliveInterval=50 -o ServerAliveCountMax=200 -o ConnectTimeout=3 -o ConnectionAttempts=5 -
DEFAULT_BECOME(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = True
DEFAULT_BECOME_ASK_PASS(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = False
DEFAULT_BECOME_METHOD(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = sudo
DEFAULT_BECOME_USER(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = root
DEFAULT_CALLBACK_WHITELIST(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = [u'profile_tasks']
DEFAULT_FORKS(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = 100
DEFAULT_HOST_LIST(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = [u'/home/saplls/git/IBM_DB2_patching/inventory']
DEFAULT_LOG_PATH(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = /home/saplls/git/IBM_DB2_patching/ansible.log
DEFAULT_REMOTE_USER(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = saplls
HOST_KEY_CHECKING(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = False
INTERPRETER_PYTHON(/home/saplls/git/IBM_DB2_patching/ansible.cfg) = auto

OS / Environment

RHEL 7

Steps to Reproduce

- name : filter stdout_lines stored in variable hosts : localhost gather_facts : no tasks : - name : capture ls output command : cmd : ls -l /etc register : ls_output # - name: show ls_output # debug: # msg: "{{ ls_output }}" - name : extract line containing rc3.d set_fact : rc3_line : " {{ ls_output.stdout_lines | regex_search('.+rc3.d.+') }} " - name : show rc3_line value debug : msg : " Line content is: {{ rc3_line }} "

Expected Results

TASK [show rc3_line value] ****************************************************************************************************************************************************************************************
Wednesday 21 July 2021 15:54:20 +0300 (0:00:00.063) 0:00:00.528 ********
ok: [localhost] => {
"msg": "Line content is: lrwxrwxrwx. 1 root root 10 Dec 3 2020 rc3.d -> rc.d/rc3.d"

Actual Results

TASK [extract line containing rc3.d] ******************************************************************************************************************************************************************************
Wednesday 21 July 2021  15:54:53 +0300 (0:00:00.405)       0:00:00.427 ******** 
fatal: [localhost]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{ ls_output.stdout_lines | regex_search('.+rc3.d.+') }}): expected string or buffer"}

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
  • Files identified in the description:

    If these files are incorrect, please update the component name section of the description or use the !component bot command.

    click here for bot help

    Which version prior to 2.9.23 did it work on?

    Using stdout_lines | regex_search actually can be used on Ansible 2.10 and 2.11 since #67823 specifically the following line:

    ansible/lib/ansible/plugins/filter/core.py Line 137 8372f34 - name : extract line containing rc3.d set_fact : rc3_line : " {{ ls_output.stdout_lines | regex_search('.+rc3.d.+') }} " - name : show rc3_line value debug : msg : " Line content is: {{ rc3_line }} "
    % ansible --version
    ansible 2.9.14
      config file = /Users/mkrizek/src/ansible/ansible.cfg
      configured module search path = ['/Users/mkrizek/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
      ansible python module location = /Users/mkrizek/src/ansible/lib/ansible
      executable location = /Users/mkrizek/.pyenv/versions/ansible-py394/bin/ansible
      python version = 3.9.4 (default, Apr  7 2021, 08:14:18) [Clang 12.0.0 (clang-1200.0.32.28)]
    
    % ansible-playbook ../ansible-issues/75296.yml
    PLAY [filter stdout_lines stored in variable] ****************************************************************************************************************
    TASK [capture ls output] *************************************************************************************************************************************
    changed: [localhost]
    TASK [extract line containing rc3.d] *************************************************************************************************************************
    fatal: [localhost]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{ ls_output.stdout_lines | regex_search('.+rc3.d.+') }}): expected string or bytes-like object"}
    PLAY RECAP ***************************************************************************************************************************************************
    localhost                  : ok=1    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0
    

    Edit:
    On Python 2 the error is expected string or buffer.