---
# file: main.yml
- hosts: fotk
remote_user: fakesudo
tasks:
- name: create a developer user
user: name={{ user }}
password={{ password }}
You can also do pre_tasks: and post_tasks: if you need to do things before or after. From the Docs https://docs.ansible.com/playbooks_roles.html
- hosts: localhost
pre_tasks:
- shell: echo 'hello in pre'
roles:
- { role: some_role }
tasks:
- shell: echo 'in tasks'
post_tasks:
- shell: echo 'goodbye in post'
>
Gives the output: PLAY [localhost]
GATHERING FACTS *************************************************************** ok: [localhost]
TASK: [shell echo 'hello in pre'] ********************************************* changed: [localhost]
TASK: [some_role | shell echo 'hello from the role'] ************************** changed: [localhost]
TASK: [shell echo 'in tasks'] ************************************************* changed: [localhost]
TASK: [shell echo 'goodbye in post'] ****************************************** changed: [localhost]
PLAY RECAP ******************************************************************** localhost : ok=5 changed=4 unreachable=0
failed=0
This is with ansible 1.9.1