首页 > 解决方案 > postgresql_query ansible 模块不处理命令中的反斜杠

问题描述

运行 yml 文件时,包含反斜杠的命令返回语法错误

有没有使用反斜杠运行命令的方法?

例如

- name: 
  hosts: 
  tasks:
    - postgresql_query:
       ...
       path_to_script: db.sql


db.sql
...
\c db

标签: ansible

解决方案


根据文档postgresql_query有一个参数db

- name: Run pgsql queries from script
  postgresql_query:
    db: <Name of database to connect to and run queries against>
    path_to_script: <path to a SQL script on the target machine>

使用它连接到数据库,然后从 SQL 脚本运行查询。

根据您的问题描述,您似乎尝试从 SQL 脚本中连接到数据库。


推荐阅读