Ansible 命令引号
Ansible command quotes
我想将以下命令集成到 Ansible 剧本任务中:
cut -f 1 -d: /etc/passwd | xargs -n 1 -I {} bash -c ' echo -e "\n{}" ; chage -l {}'
。
里面的任何引号都会破坏整个命令。我怎样才能避免它 运行 整个字符串?
非常感谢。
您可以使用 \”
转义它们
示例:"hello=\"hi\""
您可以简单地使用 YAML 文字块字符串语法。这样你就不需要转义任何引号。相反,您可以按原样传递 shell 命令。
示例:
- name: test task
shell:
cmd: |
cut -f 1 -d: /etc/passwd | xargs -n 1 -I {} bash -c ' echo -e "\n{}" ; chage -l {}'
tags: test
我想将以下命令集成到 Ansible 剧本任务中:
cut -f 1 -d: /etc/passwd | xargs -n 1 -I {} bash -c ' echo -e "\n{}" ; chage -l {}'
。
里面的任何引号都会破坏整个命令。我怎样才能避免它 运行 整个字符串?
非常感谢。
您可以使用 \”
示例:"hello=\"hi\""
您可以简单地使用 YAML 文字块字符串语法。这样你就不需要转义任何引号。相反,您可以按原样传递 shell 命令。
示例:
- name: test task
shell:
cmd: |
cut -f 1 -d: /etc/passwd | xargs -n 1 -I {} bash -c ' echo -e "\n{}" ; chage -l {}'
tags: test