在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替换为您要执行的命令。