0

i basically want to take dynamic information from my remote host whether in it is redhat or debian, and accordingly execute particular file which would be installing http packages based on os flavour.

[root@ansi1 ansible]# cat include.yml
---
 - hosts: all
   tasks:
   - name: Getting os info
     include_vars: "{{ ansible_os_family }}.yml"

   - include: setup-RedHat.yml
     when: ansible_os_family == 'RedHat'
[root@ansi1 ansible]#
[root@ansi1 ansible]#
[root@ansi1 ansible]#
[root@ansi1 ansible]# cat setup-RedHat.yml
---
 - hosts: all
   tasks:
   - name: htttp install
     yum: name=httpd state=present

ansible-playbook include.yml

Error:

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The error appears to have been in '/etc/ansible/setup-RedHat.yml': line 2, column 4, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
 - hosts: all
   ^ here


The error appears to have been in '/etc/ansible/setup-RedHat.yml': line 2, column 4, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
 - hosts: all
   ^ here

2 Answers 2

2

When you use the include module in a tasks section, you cannot include a playbook, you can only include a list of tasks. That means that your file setup-RedHat.yml should only contain the following:

- name: htttp install
  yum: name=httpd state=present

- name: more tasks...
0

include_vars directive is meant for taking Ansible variables for the current playbook from the file given as the value. In this case, the variables are (presumable declared in and) inherited from the file "{{ ansible_os_family }}.yml".

ansible_os_family is a fact that Ansible gathers automatically from the remote system, it resolves to the parent distribution (if any) of the distribution in context or itself if there is no parent. So, for example, if you are running this on a Debian derivative, the filename to look out for becomes Debian.yml.

1
  • i have edited the question, plz look, later i would be adding the debian.yml file Jun 9, 2017 at 9:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .