【发布时间】:2015-05-10 15:26:11
【问题描述】:
使用 Ansible 原始模块实现 mysql 请求的正确方法是什么?
ansible host -m raw -a 'mysql mydb -e "SELECT lastname FROM table WHERE fistname = 'Joe'"' --su -vvvv
这不起作用并给我以下输出
<host>
<host> PubkeyAuthentication=no ConnectTimeout=10 'su root -c "$SHELL -c '"'"'echo SUDO-SUCCESS-sbqanpltaxkqfzxjdnpjytpnytyhrvow; mysql mydb -e "SELECT lastname FROM table WHERE firstname=Joe"'"'"'"' GSSAPIAuthentication=no User=user ControlPath=/home/user/.ansible/cp/ansible-ssh-%h-%p-%r ControlMaster=auto ControlPersist=60s
host | FAILED | rc=1 >>
value: -c: line 0: unexpected EOF while looking for matching `''
value: -c: line 1: syntax error: unexpected end of file
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 1
Shared connection to host closed.
ERROR 1054 (42S22) at line 1: Unknown column 'firstname' in 'where clause'
如果我想逃跑:
ansible host -m raw -a 'mysql mydb -e \"SELECT lastname FROM table WHERE fistname = 'Joe'\"'
Ansible 删除命令中的单引号,给出此输出:
<host>
<host> PubkeyAuthentication=no ConnectTimeout=10 GSSAPIAuthentication=no User=user 'su root -c "$SHELL -c '"'"'echo SUDO-SUCCESS-dmbzdeiqiygmuoebxlswxfzdaxxutgqp; mysql mydb -e \"SELECT value FROM table WHERE firstname=Joe\"'"'"'"' ControlPath=/home/user/.ansible/cp/ansible-ssh-%h-%p-%r ControlMaster=auto ControlPersist=60s
host | FAILED | rc=1 >>
ERROR 1054 (42S22) at line 1: Unknown column 'firstname' in 'where clause'
debug3: mux_client_read_packet: read header failed: Broken pipe
debug2: Received exit status from master 1
Shared connection to host closed.
【问题讨论】:
标签: mysql escaping quotes ansible