Я пытаюсь передать две переменные, содержащие имена хостов, в роль. Эти имена хостов будут user как hosts: values.
Я пытался так.
- hosts: host1,host2
roles:
- role: role1
oldhost: host1
newhost: host2
И так.
- hosts: host1,host2
tasks:
- name: Transfering tar files.
include_role:
name: role1
vars:
oldhost: host1
newhost: host2
Но что бы я ни делал, я получаю следующую ошибку:
ERROR! unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'>
The error appears to be in '/etc/ansible/custom/1943Asco/app/roles/userdata/tasks/main.yml': line 2,
column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- hosts: "{{oldhost | default('Invalid old host') }}"
^ 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 }}"
Это мой main.yml. У меня есть второй сразу после этого для host2.
---
- hosts: "{{ oldhost| default('Invalid host1') }}"
vars:
first: "$HOME/first.tar.gz"
second: "$HOME/second.tar.gz"
third: "$HOME/third.tar.gz"
fourth: "$HOME/fourth.tar.gz"
tasks:
- name: Copy file from remote node onto local server.
fetch:
src: "{{item}}"
dest: "/path/to/item/"
flat: yes
fail_on_missing: no
with_items:
- "{{first}}"
- "{{second}}"
- "{{third}}"
- "{{fourth}}"
- name: Delete the tar file
local_action: file path="{{item}}" state=absent
with_items:
- "{{first}}"
- "{{second}}"
- "{{third}}"
- "{{fourth}}"
Может ли кто-нибудь помочь мне с этим?
РЕДАКТИРОВАТЬ
Я думаю, что проблема заключается в том, что у меня могут быть только задачи в файле main.yml. И я прошел 2 пьесы.