wiki:ansible

### Jeff Geerling's ansible tutorial

- https://www.youtube.com/playlist?list=PL2_OBreMn7FqZkvMYt6ATmgC0KAGGJNAN

### Inspiration

- Jeff Geerling makes a whole bunch of high quality ansible roles (https://ansible.jeffgeerling.com/ for full list)
  - https://github.com/geerlingguy/internet-pi simple example deploying a few docker containers onto a server
  - https://github.com/geerlingguy/ansible-role-nginx example of somewhat advanced jinja templating
- https://github.com/freeipa/ansible-freeipa enormous ansible project
- https://gitlab.archlinux.org/archlinux/infrastructure Arch linux's infrastructure is based on ansible and terraform. Cool real world use case

### Testing jinja templates

Ansible on it's own doesn't have a convenient way to preview what templates will be rendered as. Luckily there's an online tool to help with that:

- https://jinjafx.io/

### Linting

Ansible provides a tool that checks your ansible files for best practices.

To lint a specific file or automagically detect what to lint:

ansible-lint ansible-lint

If using vim, the following snippet can be used to run ansible-lint inside the editor. By running :make, all the ansible-lint errors will be pulled into vim's quickfix list:

autocmd BufRead,BufNewFile *.ymlyml

\ set makeprg=ansible-lint\ -p errorformat=%f:%l:\ [E%n]\ %m,%f:%l:\ [EANSIBLE%n]\ %m,%f:%l:\ [ANSIBLE%n]\ %m,%f:%l:%c:\ %m,%f:%l:\ %m

note: this changes makeprg & errorformat for all yml files which might not be what you want

wiki/ansible.txt · Last modified: 2024/08/25 21:38 by admin