首页 > 解决方案 > ansible中的regex_findall中的变量

问题描述

- name: Get names for all running Oracle databases from oratab file
  slurp:
    src: /etc/oratab
  register: oracle_patch_oratab

- name: Extract a list of DBs which mataches the Oracle Home
  set_fact:
    oracle_patch_dblist: "{{ oracle_patch_oratab['content'] | b64decode | regex_findall ('(.+v12201.+)', multiline=True, ignorecase=True) }}"

在 regex_findall 中,我将一个值硬编码为 v12201,我想用变量替换它。如果是这样,在 regex_findall 中使用的语法是什么?提前致谢。

标签: ansible

解决方案


我尝试了以下方法,效果很好。

- name: Get names for all running Oracle databases from oratab file
  slurp:
    src: /etc/oratab
  register: oracle_patch_oratab      

- name: "assign pattern"
  set_fact: 
    ora_ver: "12201"

- name: Extract a list of DBs which mataches the Oracle Home
  set_fact:
    oracle_patch_dblist: "{{ oracle_patch_oratab['content'] | b64decode | regex_findall ('(.+' + ora_ver | string + '.+)', multiline=True, ignorecase=True) }}"

推荐阅读