Я создал .YML Playbook.
Поместите в него какой-то код, он отлично работает.
Затем я столкнулся с проблемой - я пытаюсь автоматизировать развертывание определенногоприложение.Приложение запрашивает взаимодействие с пользователем.К сожалению, «да | команда » не работает.Это просто игнорируется, и все еще подсказывает.
Итак, я решил использовать модуль Expect.
Текущий код выглядит следующим образом:
- hosts: all
remote_user: someuser
gather_facts: yes
tasks:
- name: "Copy files"
copy: src=../somefiles/ dest=/tmp
- name: "Execute some script"
shell: sudo /tmp/script.sh
- name: "Execute app"
expect:
command: /bin/bash -c 'sudo /tmp/app arguments'
responses:
"'Press 'y' to confirm ('s' to skip, 'a' to abort):'": "y"
echo: y
Я заключил в ожидаемую строку двойные кавычки.Но поскольку ожидаемая строка содержит одинарные кавычки ('), похоже, синтаксис нарушен.
Вывод ошибки следующий:
ERROR! Syntax Error while loading YAML.
The error appears to have been in 'deploy.yml': line 16, column 1, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
responses:
"'Press 'y' to confirm ('s' to skip, 'a' to abort):'": "y"
^ here
This one looks easy to fix. It seems that there is a value started
with a quote, and the YAML parser is expecting to see the line ended
with the same kind of quote. For instance:
when: "ok" in result.stdout
Could be written as:
when: '"ok" in result.stdout'
Or equivalently:
when: "'ok' in result.stdout"
We could be wrong, but this one looks like it might be an issue with
unbalanced quotes. If starting a value with a quote, make sure the
line ends with the same set of quotes. For instance this arbitrary
example:
foo: "bad" "wolf"
Could be written as:
foo: '"bad" "wolf"'
Я пробовал оба с обратной косой чертой() для экранирования символов для одинарных кавычек и двойных кавычек.Никто из них не работал.В зависимости от порядка котировок, которые я размещаю, я получаю . Это выглядит легко исправить. или прямо на плохой волк .