正确的 YAML 文件是否足以在执行角色时提供正确的 ansible 剧本和语法?
Is a correct YAML file enough for a correct ansible playbook, syntax while executing a role?
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: "The error appears to be in /home/ansible/march/roles/apache/tasks/apt.yml': line 2, ..."
A:指令 hosts
和 tasks
是 playbook but not in a role 中的有效关键字.
- hosts: all
become: yes
tasks:
Q: "Is a correct YAML file enough for a correct Ansible playbook ...?"
A:显然不是。问题中提供的剧本在句法上是正确的。 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
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: "The error appears to be in /home/ansible/march/roles/apache/tasks/apt.yml': line 2, ..."
A:指令 hosts
和 tasks
是 playbook but not in a role 中的有效关键字.
- hosts: all
become: yes
tasks:
Q: "Is a correct YAML file enough for a correct Ansible playbook ...?"
A:显然不是。问题中提供的剧本在句法上是正确的。 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