Ansible
Ansible is a IT automation tool, enabling infrastructure as code.
Quickstart
- Based on the Ansible docs
playook.yaml
- name: My first play
hosts: virtualmachines
tasks:
- name: Ping my hosts
ansible.builtin.ping:
- name: Print message
ansible.builtin.debug:
msg: Hello world
Usage
CLI
ansible-playbook -i /path/to/my_inventory_file -u my_connection_user -k -f 3 -T 30 -t my_tag -m /path/to/my_modules -b -K my_playbook.yml
Loads my_playbook.yml
from the current working directory and:
-i
- usesmy_inventory_file
in the path provided for inventory to match the pattern.-u
- connects over SSH asmy_connection_user
.-k
- asks for password which is then provided to SSH authentication.-f
- allocates 3 forks.-T
- sets a 30-second timeout.-t
- runs only tasks marked with the tagmy_tag
.-m
- loads local modules from/path/to/my/modules
.-b
- executes with elevated privileges (uses become).-K
- prompts the user for the become password.
Useful Tasks
Add Ubuntu repository
- name: Add HashiCorp repo
block:
- name: Download GPG key
ansible.builtin.get_url:
url: https://apt.releases.hashicorp.com/gpg
dest: /etc/apt/trusted.gpg.d/hashicorp.asc
- name: Add repo
ansible.builtin.apt_repository:
repo: "deb [signed-by=/etc/apt/trusted.gpg.d/hashicorp.asc] https://apt.releases.hashicorp.com {{ ansible_distribution_release }} main"
state: present
Add user to group
- name: Ensure "docker" group exists
ansible.builtin.group:
name: docker
state: present
- name: Add "ubuntu" user to "docker" group
ansible.builtin.user:
name: ubuntu
groups: docker
append: true
Enable and start services
Install
Fedora
Resources
- Vagrant Docs
- Ansible Docs
Last update:
August 11, 2023
Created: June 3, 2023
Created: June 3, 2023