Below is my playbook directory structure.
/home/ansible/playbooks/
├── first.yml --> simple playbook with no roles works fine.
├── playbook.yml --> main playbook with roles
└── roles
└── webservers
├── default
│ └── main.yml
├── handler
│ └── main.yml
├── tasks
│ └── main.yml
└── vars
└── main.yml
My main playbook code below :
--- #playbook with roles
- hosts: webserver
user: ansible
become: yes
become_method: sudo
connection: ssh
gather_facts: yes
roles:
- webservers
My /roles/webserver/tasks/main.yml code :
- name: Install httpd on redhat
yum:
- pkg: httpd
state: latest
notify: installed_httpd
when: ansible_os_family == 'RedHat'
- name: Install apache2 on debian
apt:
- pkg: apache2
state: latest
notify: installed_apache
when: ansible_os_family == 'Debian'
My /roles/webserver/handlers/main.yml code :
- name: installed_httpd
service:
- name: httpd
state: restarted
- name: installed_apache
service:
- name: apache2
state: restarted
When I execute playbook, getting the following error :
ERROR! unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'>
The error appears to have been in '/home/ansible/playbooks/roles/webservers/tasks/main.yml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Install httpd on redhat
^ here
I checked all the questions related to this error but all seems to related improper syntax or incorrect indentation.
I have checked same in my files and all seems fine and also worked without error if I run playbook without roles with all tasks and handlers defined in the same playbook.
Ansible version: 2.7.2 python2 version: 2.7.5 python3 version: 3.7.1