Ansible

Befehl ausführen

Debugging

- name: Play to get the gathre facts content
  hosts: DEV1
  tasks:
  - name: print ansible_facts
    debug:
     var: ansible_facts["kernal"]

Playbook

ansible-playbook -l hosts playbook.yml
ansible-playbook --limit hosts playbook.yml
ansible-playbook --syntax-check playbook.yml

Roles

Use su

become: yes
become_user: username
#su: yes
#su_user: username

Vault Secrets

ansible-vault encrypt secrets.yaml
ansible-vault decrypt secrets.yaml
EDITOR=vim ansible-vault edit secrets.yml
ansible-playbook playbook.yaml --ask-vault-password
ansible-playbook playbook.yaml --ask-password-file FILES
ansible-playbook --vault-password-file /path/to/my/vault-password-file site.yml
ansible-playbook --vault-password-file my-vault-password-client.py
- name: Load Secrets
  include_vars:
    file: secrets.yaml
    name: secrets

Lokal ausführen

ansible-playbook -i "localhost," -c local workstation.yml

User sudo with a password

Loops

Playbook Examples

Variablen

- debug:
  args:
    msg: 'System {{ ansible_distribution_release }}'
ansible host -m setup
name: Ansible check directory exists
stat:
  path: /etc/pihole
register: folderstat
debug:
  msg: "{{ folderstat }}"

Commandline

Variables

- name: Include vm variables
  include_vars:
    file: vars/vms.yml
    name: vms
set_fact:
  vm: "{{ vms.all.hosts[fqdn] }}"

Docker

- name: Create a data container
  community.docker.docker_container:
    name: mydata
    image: busybox
    volumes:
      - /data