1
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

The playbook(apt.yml) which contains:

---
- hosts: all
  become: yes
  tasks:
  - name: uninstall git
    apt:
      name: git
      state: absent
  - name: update
    apt:
      update-cache: yes
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63

1 Answers1

0

Q: "The error appears to be in /home/ansible/march/roles/apache/tasks/apt.yml': line 2, ..."

A: The directives hosts and tasks are valid keywords in a playbook but not in a role.

- hosts: all
  become: yes
  tasks:

Q: "Is a correct YAML file enough for a correct Ansible playbook ...?"

A: It is not, obviously. The playbook presented in the question is syntactically correct. ansible-lint apt.yml, yamllint apt.yml, and ansible-playbook apt.yml --syntax-check report no errors.

The playbook was tested with the inventory

shell> cat hosts
linux:
  hosts:
    test_01:
      ansible_host: 10.1.0.11

The playbook works as expected

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
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63