brain/src/ops/tools/ansible.md
2019-07-07 21:21:48 +02:00

1.2 KiB

Ansible

List all tags

ansible-playbook -i host.targets -v site.yml --list-tags

Start at a specific task (life savior)

ansible-playbook -i host.targets -v site.yml --start-at-task "The audacious task"

List hosts

ansible-playbook -i host.targets -v site.yml --list-hosts

Limit hosts

ansible-playbook -i host.targets -v site.yml --limit hostname

Jinja2, templates & carriage return

To tell Jinja2 to not mess with carriage return in templates add

#jinja2: trim_blocks:False
---

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.

- 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 false.

Exec task(s) if a specific service is found

- 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"