Ansible читать и запускать команду из файла - PullRequest
0 голосов
/ 07 августа 2020

помогите, пожалуйста, с ansible. У меня есть текстовый файл с командами, устанавливающими некоторые переменные в начале установки. Например:

X=value1
Y=value2

Мне нужно прочитать и запустить их один за другим в al oop

Я пробую этот код:

- name: read and run commands from file
  command: {{item}}
  loop: "{{ lookup('file', 'tf_ansible_commands').splitlines() }}"

, но получаю ошибку

ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: No JSON object could be decoded

Syntax Error while loading YAML.
  found unacceptable key (unhashable type: 'AnsibleMapping')

The error appears to be in '/home/username/file.yml': line 21, column 18, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

    - name: read and run commands from file
      register: {{ item }}
                 ^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"

Если я добавлю кавычки, например "{{item}}", он начнет работать, но выдает ошибку, поскольку эта команда не работает из-за кавычек.

Как можно Я решаю этот вопрос? Я уверен, что должен быть какой-то обходной путь. Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...