- apt: pkg=vim state=present # task one-line
- apt:
pkg: vim
state: present
- hosts:all
user: root
sudo: no
vars:
aaa: "bbb"
tasks:
-
- name: my task
command: my_command
register: result
failed_when: "'FAILED' in result.stderr"
ignore_errors: yes
change_when: "result.rc != 2"
tasks:
- include: db.yml
handlers:
- include: db.yml user=timo
handlers:
- name: start apache2
action: service name=apache2 state=started
tasks:
- namne: install apache
action: apt pkg=apache2 state=latest
notify: start apache2
- host: development
vars_files:
- vars.yml
vars:
project_root: /var/www/virtual
tasks:
- name: Create the SSH directory
file:
- state: directory
- path: "{{project_root}}/home/.ssh"
only_if: "$vm == 0"
vars:
local_name: "{{ lookup('env', 'HOME') }}"
roles/
common/
tasks/
handlers/
files/ # `copy` will refer to this folder
templates/ # `template` will refer to this folder
meta/ # role dependencies here
vars/
defaults/
main.yml
- host: xxx
roles:
- db
- web
# roles/db/tasks/*.yml
# roles/web/handlers/*.yml
to become another user, the default value of become_user is root
- name: ensure the nginx is running as the vagrant user
service:
name: nginx
state: started
become: true
become_method: sudo
become_user: vagrant
# Add the user 'vagrant' with a specific uid and a primary group of 'admin'
- user:
name: vagrant
comment: "John Doe"
uid: 1040
group: admin
# Add the user 'james' with a bash shell, appending the group 'admins' and 'developers' to the user's groups
- user:
name: james
shell: /bin/bash
groups: admins,developers
append: yes
# Remove the user 'john'
- user:
name: john
state: absent
remove: yes
# Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa
- user:
name: jsmith
generate_ssh_key: yes
ssh_key_bits: 2048
ssh_key_file: .ssh/id_rsa
# added a consultant whose account you want to expire
- user:
name: james18
shell: /bin/zsh
groups: developers
expires: 1422403387
-
pre_tasks:
-
register:
-
assert:
-
with_items:
-
roles:
-
handlers:
-
service: