ERROR!
"unexpected parameter type in action: class 'ansible.parsing.yaml.objects.AnsibleSequence'"
The error appears to be in '/home/ansible/march/roles/apache/tasks/apt.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: all
^ here
剧本(apt.yml(包含:
---
- hosts: all
become: yes
tasks:
- name: uninstall git
apt:
name: git
state: absent
- name: update
apt:
update-cache: yes
Q:"错误出现在/home/ansible/march/roles/apache/tasks/apt.yml':第2行,…">
A:指令hosts
和tasks
在剧本中是有效关键字,但在角色中不是。
- hosts: all
become: yes
tasks:
Q:"一个正确的YAML文件是否足以制作正确的Ansible剧本…?">
显然不是。问题中提出的策略在语法上是正确的。ansible-lint apt.yml
、yamllint apt.yml
和ansible-playbook apt.yml --syntax-check
未报告错误。
战术手册已通过库存进行了测试
shell> cat hosts
linux:
hosts:
test_01:
ansible_host: 10.1.0.11
战术手册如预期
shell> ansible-playbook apt.yml -C
PLAY [all] ***
TASK [Gathering Facts] ***
ok: [test_01]
TASK [uninstall git] ***
changed: [test_01]
TASK [update] ***
changed: [test_01]
PLAY RECAP ***
test_01: ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0