2017-11-03 10:32:05 +00:00
|
|
|
# Ansible
|
|
|
|
|
|
|
|
## List all tags
|
|
|
|
|
|
|
|
```shell
|
|
|
|
ansible-playbook -i host.targets -v site.yml --list-tags
|
|
|
|
```
|
|
|
|
|
|
|
|
## Start at a specific task (life savior)
|
|
|
|
|
|
|
|
```shell
|
|
|
|
ansible-playbook -i host.targets -v site.yml --start-at-task "The audacious task"
|
|
|
|
```
|
|
|
|
|
|
|
|
## List hosts
|
|
|
|
|
|
|
|
```shell
|
|
|
|
ansible-playbook -i host.targets -v site.yml --list-hosts
|
|
|
|
```
|
2017-11-15 09:59:46 +00:00
|
|
|
|
|
|
|
## Limit hosts
|
|
|
|
|
|
|
|
```shell
|
|
|
|
ansible-playbook -i host.targets -v site.yml --limit hostname
|
|
|
|
```
|
2018-01-17 09:11:03 +00:00
|
|
|
|
|
|
|
## Jinja2, templates & carriage return
|
|
|
|
|
|
|
|
To tell Jinja2 to not mess with carriage return in templates add
|
|
|
|
|
2019-07-07 19:21:48 +00:00
|
|
|
```jinja
|
2018-01-17 09:11:03 +00:00
|
|
|
#jinja2: trim_blocks:False
|
|
|
|
---
|
|
|
|
```
|
|
|
|
|
2019-06-26 10:11:43 +00:00
|
|
|
at the top of the template file
|
|
|
|
|
|
|
|
## Import vs include (kudos @href)
|
|
|
|
|
|
|
|
If you want to exec a sets of tasks when a condition is true, use
|
|
|
|
import_tasks.
|
|
|
|
|
2019-06-29 19:27:22 +00:00
|
|
|
```yaml
|
2019-06-26 10:11:43 +00:00
|
|
|
- name: Include init tasks
|
|
|
|
import_tasks: init.yml
|
|
|
|
tags:
|
|
|
|
- init
|
|
|
|
when: proof.stat.exists == False
|
|
|
|
```
|
|
|
|
|
|
|
|
`ìnclude_tasks` will add all tasks to play run, even if the when condition is
|
2019-06-29 19:27:44 +00:00
|
|
|
false.
|
|
|
|
|
|
|
|
## Exec task(s) if a specific service is found
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
- name: Is Docker running ?
|
|
|
|
service_facts:
|
|
|
|
|
|
|
|
- name: Push Telegraf docker input config if needed
|
|
|
|
template:
|
|
|
|
src: inputs/input.docker.conf.j2
|
|
|
|
dest: /etc/telegraf/telegraf.d/input.docker.conf
|
|
|
|
notify: reload telegraf
|
|
|
|
when: "'docker' in services"
|
2019-07-07 19:21:21 +00:00
|
|
|
```
|