Назад | Перейти на главную страницу

Печатать вывод отладки Ansible без кавычек / экранирования

Мне нужно знать, есть ли способ распечатать информацию из доступного playbook, который не заставляет ansible автоматически цитировать и экранировать строку. Например, я использую ansible для создания команды, которая должна запускаться отдельно с другой машины (иронично, я знаю, но все равно необходимо). В настоящее время результат выглядит примерно так ...

"command" = "run_me.sh \"with this argument\""

Мне нужно что-то вроде ...

"command" = run_me.sh "with this argument"

или просто...

run_me.sh "with this argument" 

если возможно, но я предполагаю, что это слишком много.

В настоящее время я использую set_fact для создания команды и отладки для ее печати.

Вы можете написать свой собственный плагин обратного вызова stdout или использовать некоторые из этих приемов:

---
- hosts: localhost
  gather_facts: no
  tasks:

    # Print as loop item
    - name: Print command as loop item
      set_fact:
        dummy: value # Just to make some task without output
      with_items:
        - 'Execute this: run_me.sh "with this argument"'

    # Print as task title
    # Not suitable for different commands per host, because task title is common for all hosts
    - name: 'Execute this: run_me.sh "with this argument"'
      debug:
        msg: Execute command from task title

    # Print as pause statement
    # Not suitable for different commands per host, because pause task skips host loop (forced run_once:yes)
    - name: Print command as pause statment
      pause:
        prompt: 'Execute this and press enter: run_me.sh "with this argument"'

Вывод:

TASK [Print command as loop item] **********************************************
ok: [localhost] => (item=Execute this: run_me.sh "with this argument")

TASK [Execute this: run_me.sh "with this argument"] ****************************
ok: [localhost] => {
    "msg": "Execute command from task title"
}

TASK [Print command as pause statment] *****************************************
[Print command as pause statment]
Execute this and press enter: run_me.sh "with this argument":
ok: [localhost]