在Ansible中,可以使用quote
过滤器来设置额外的引号,并使用block
和when
语句来打断执行。以下是一个示例解决方法:
- name: Example playbook
hosts: your_hosts
gather_facts: false
tasks:
- name: Set extra quotes
set_fact:
extra_quotes: '"'
- name: Execute command with extra quotes
block:
- name: Run command with extra quotes
shell: "{{ your_command | quote }}"
when: extra_quotes is defined and extra_quotes == '"'
在上面的示例中,首先使用set_fact
任务设置了一个名为extra_quotes
的变量,值为"
。然后,使用block
语句将要执行的命令包装起来,以防止在when
语句中打断执行。最后,在shell
模块中使用quote
过滤器将命令设置为额外的引号。
请将your_hosts
替换为您要操作的主机组,将your_command
替换为您要执行的命令。