Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible tag include_role is not working for ansible version 2.3

Tags:

ansible

I have following playbook

- name: Restart Apache Server
  hosts: "{{ host }}"
  include_role: 
    name: root
    tasks_from: apache-restart.yml
  become: true
  become_user: root

When I am running this playbook it is throwing me the following error

ERROR! 'include_role' is not a valid attribute for a Play

The error appears to have been in '/Users/Atul/Workplace/infra-automation/deployments/LAMP/site.yml': line 18, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: Restart Apache Server
  ^ here

Following are the details of Ansible installed in my laptop.

ansible 2.3.1.0
  config file = /Users/Atul/Workplace/infra-automation/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Apr  4 2017, 08:47:57) [GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.38)]
like image 722
Atul Agrawal Avatar asked Dec 23 '22 14:12

Atul Agrawal


2 Answers

include_role is a an action module to use in tasks.

For plays you should use role directive similar to https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html#using-roles.

like image 53
techraf Avatar answered May 20 '23 18:05

techraf


techraf is correct, you can use include_role in the tasks. This is a working example from tasks/main.yml in one of my roles:

- name: intranet is a plone3 application
  include_role:
    name: plone3
    private: yes
  vars:
    plone3_version: "{{intranet_plone3_version}}"
like image 34
René Pijl Avatar answered May 20 '23 18:05

René Pijl