Ansible Playbooks
General
- Community Playbooks: Ansible Galaxy
- Install with
ansible-galaxy collection install my_namespace.my_collection
- Install with
- Ansible
register
is a way to capture the output from task execution and store it in a variable. - If you start a value with
{{ foo }}
, you must quote the whole expression to create valid YAML syntax
Examples
Ansible Linux Demos - Github ansible/product-demos
Ansible Playbook: Esnure nano is installed
Ansible Playbook: APT Update & Upgrade
Run with: ansible-playbook ansible/apt.yml --user myname --ask-pass --ask-become-pass -i ansible/hosts
Notify Ansible Handlers
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_handlers.html#handler-example
- name: Verify apache installation
hosts: webservers
vars:
http_port: 80
max_clients: 200
remote_user: root
tasks:
- name: Write the apache config file
ansible.builtin.template:
src: /srv/httpd.j2
dest: /etc/httpd.conf
notify:
- Restart apache
handlers:
- name: Restart apache
ansible.builtin.service:
name: httpd
state: restarted