I have a host with 2 servers: one has CentOS and the other Ubuntu installed.
I decided to install apache, nginx and php-fpm on both servers and wrote 3 playbooks.
- ubuntu.yml (/home/ansible/playbook):
---
- name: Ubuntu Playbook
hosts: ubun
become: true
vars:
- packages:
- nginx
- apache2
- php-fpm
tasks:
- name: Update apt package
apt:
name: "*"
state: latest
update_cache: yes
- name: Install Packages
apt:
pkg: "{{ packages }}"
state: latest
update_cache: yes
- name: Apache Service Start
service:
name: nginx
state: restarted
enabled: yes
- centos.yml (/home/ansible/playbook):
---
- name: CentOS Playbook
hosts: cent
become: true
vars:
packages:
- epel-release
- httpd
- nginx
- php-fpm
tasks:
- name: Update yum package
yum:
name: "*"
state: latest
update_cache: yes
- name: Install Packages
yum:
name: "{{ packages }}"
state: latest
update_cache: yes
- name: Apache Service Start
service:
name: nginx
state: restarted
enabled: yes
- base.yml (/home/ansible/playbook):
---
- name: Base Playbook
hosts: aws
become: true
tasks:
- name: Performing Tasks for CentOS
when: ansible_facts['distribution'] == 'CentOS'
include_tasks: centos.yml
- name: Performing Tasks for Ubuntu
when: ansible_facts['distribution'] == 'Ubuntu'
include_tasks: ubuntu.yml
My 3 Ansible groups are:
[aws] which contains both the server
[cent] which contains CentOS server
[ubun] which contains Ubuntu server
I tried dry running centos.yml
and ubuntu.yml
separately and it worked, but when I try dry running base.yml
the following error is raised:
FAILED! => {"reason": "unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'>\n\nThe error appears to be in '/home/ansible/playbook/centos.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: CentOS Playbook\n ^ here\n"}
FAILED! => {"reason": "unexpected parameter type in action: <class 'ansible.parsing.yaml.objects.AnsibleSequence'>\n\nThe error appears to be in '/home/ansible/playbook/ubuntu.yml': line 2, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Ubuntu Playbook\n ^ here\n"}
I already tried replacing import_tasks
with include_tasks
but I get the same error.