askpython
askpython

Reputation: 85

roles overides tasks in playbook

I have ansible playbook which look similar to the code below :

---
- hosts: localhost
 connection: local

 tasks:
 - name: "Create custom fact directory
   file:
    path: "/etc/ansible/facts.d"
    state: "directory"

 - name: "Insert  custom fact file"
   copy:
    src:  custom_fact.fact
    dest: /etc/ansible/facts.d/custom_fact.fact
    mode: 0755

roles:
- role1
- role2

once i am running the playbook with ansible-playbook command only the roles is running ,but the tasks is not getting ran

if i am remarking the roles from the playbook,the task gets ran

how can i make the task to run before the roles ?

Upvotes: 0

Views: 38

Answers (2)

Vladimir Botka
Vladimir Botka

Reputation: 68189

Correct the indentation

- hosts: localhost
  connection: local
  tasks:
    - name: "Create custom fact directory
      file:
        path: ...

Upvotes: 0

Derrick Xu
Derrick Xu

Reputation: 61

Put the tasks in a section pre_tasks which are run before roles.

You may also find post_tasks useful which run tasks after roles.

Upvotes: 1

Related Questions