python - 错误为 : re. 错误:运行 ansible playbook 时全局标志不在位置 1 表达式的开头

标签 python ansible ansible-inventory

有人可以协助如何解决此问题吗?为什么我在运行 Ansible playbook 时遇到此错误

2023-03-31 11:47:39,902 p=57332 u=NI40153964 n=ansible | An exception occurred during task execution. To see the full traceback, use -vvv. The error was: re.error: global flags not at the start of the expression at position 1 2023-03-31 11:47:39,903 p=57332

Python 和 Ansible 版本:

  • Python 3.11.2
  • Ansible [核心 2.14.3]

我正在使用的 YML 文件

    - name: rename log file to user specific
      delegate_to: localhost
      command: mv ~/.ansible/wmDeployment.log ~/.ansible/wmDeployment_{{_user}}.log
      register: logfile_rename_output
      run_once: true
      ignore_errors: yes

    - name: set the fact for email
      set_fact:
        package_list: "{{hostvars['localhost']['package_list']}}"
        log_output: "{{log_data| regex_search('((?s)(?<=This task is to install package in target servers).*?(?=This task is to enable kafka consumers and send mail of playbook log))')}}"
        emailkey: code
        cacheable: true

最佳答案

错误消息表明您需要将 (?s) 放在正则表达式的最开头。或者,尝试类似的方法

    log_output: "{{log_data| regex_search('(?s:(?<=This task is to install package in target servers)(.*?)(?=This task is to enable kafka consumers and send mail of playbook log))"

关于python - 错误为 : re. 错误:运行 ansible playbook 时全局标志不在位置 1 表达式的开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75895460/

相关文章:

ansible - 如何在带有变量的 YAML 中使用 IF ELSE?

ansible - 在 Ansible 中,如何使用键的变量更改现有字典/哈希值

ansible - 如何创建包含默认情况下不应运行的任务的角色

Ansible set_fact 本地并在远程主机上使用

python - Ansible Python API - 如何获取在 vars_files、host_vars、group_vars 中定义的变量

python - Django - 一次处理多个文件上传请求?

python - 快速 python 前端列表扩展

python - 没有 BS4 python 类的刮表

python - AWS lambda在每次调用时更新sts角色非常耗时

ansible - 目标主机文件中的 Ansible 嵌套子组