[root@master ansible-playbook-roles]# ansible -i host/hosts mysql -m shell -a "echo '!Love' >> ~/test.txt"
-bash: !Love: event not found
如果涉及传输类似包含特殊字符的字符串,需要进行转义,不然会有类似报错
解决方式一
使用反斜杠/进行转义,并且用双引号包含
[root@master ansible-playbook-roles]# ansible -i host/hosts mysql -m shell -a "echo "\!Love" >> ~/test.txt"
node5 | CHANGED | rc=0 >>
解决方式二
使用双引号包含单引号再包含内容
[root@master ansible-playbook-roles]# ansible -i host/hosts mysql -m shell -a "echo "'rrr!Love'" >> ~/test.txt"
node5 | CHANGED | rc=0 >>