echothrust/howtos

A list of OpenBSD (mostly) material

View on GitHub

Manage OpenBSD hosts using ansible

First steps with ansible

All Ansible commands follow the pattern:

ansible <server_or_group> -m module_name -a arguments

Run ansible test on OpenBSD host (requires python2.7 installed):

ansible all -u sysadmin -i www.echoctf.dev, -m ping -e 'ansible_python_interpreter=/usr/local/bin/python2.7'

Ansible host inventory

Create inventory location:

mkdir ~/work/ansible
touch ~/work/ansible/hosts
touch ~/.ansible.cfg

Open ~/.ansible.cfg file to specify the inventory location:

[defaults]
inventory = ~/work/ansible/hosts

Create entries in ~.work/ansible/hosts file:

kerberus.wks.echothrust.dev
mail.echothrust.dev

[webservers]
www.echoctf.dev
support.echothrust.dev
www.echothrust.dev

Creating playbooks

A playbook is a YAML file, and typically follows this structure:

---
- hosts: [target hosts]
  remote_user: [yourname]
  tasks:
    - [task 1]
    - [task 2]

For example, the following playbook will create a file on all servers in the webservers group

---
- hosts: [webservers]
  remote_user: sysadmin
  tasks:
    - name: Create /tmp/somefile.test
      command: touch /tmp/somefile.test
      become: True
      become_method: doas

Relevant post about doas, ansible and env vars

Running playbooks

Assuming you are in the same directory as a playbook file, run:

ansible-playbook myplaybook.yml

If you want to see what hosts this playbook will affect without having to open up the YAML file, you can run:

ansible-playbook myplaybook.yml --list-hosts

If you want to see what tasks will run on a specific host:

ansible-playbook myplaybook.yml -i www.echoctf.dev, --list-tasks

Use the “batteries included”

Ansible ships with a large collection of modules that you can run as tasks or via ad-hoc commands. To see a listing of all available modules, run:

ansible-doc -l

The list is quite large… some interesting modules follow.

Commands:

Files:

Package management:

Operating system:

Various: