Some of the templates I've created to clean up my Ansible configs!
Template | Functionality |
---|---|
docker.yaml | Copies files, stops & starts docker compose |
service.yaml | Copies files, links .service file, stops service, reloads daemon, starts service |
setup-user-docker-ssh.yaml | Ensure user exists, add user to docker group, add ssh keys |
sudoers-allow-service-management.yaml | Allow specified user to manage specified service |
Either ...
- Copy the contents of one (or more) of the yaml files
- Use
git clone https://github.com/Denperidge/ansible-templates.git templates
to get all templates
Example usage:
- name: Server setups
hosts: servers
tasks:
- include_tasks: templates/docker.yaml
vars:
name: "Plausible"
src: "./plausible-files/"
dest: "/home/user/plausible"
Note: click here to view the explanation as to why no docker compose module is used
- name: Server setups
hosts: servers
tasks:
- include_tasks: templates/service.yaml
vars:
name: "caddy"
src: "./caddy/"
dest: "/home/user/caddy"
servicefile: "/home/user/caddy/caddy.service"
- name: Server elevated setups
hosts: servers
become_user: root
tasks:
- include_tasks: templates/setup-user-docker-ssh.yaml
loop:
- {
username: "root",
sshkeys:
[
{comment: "Desktop pc", file: "keys/id_rsa_desktop.pub"},
{comment: "Laptop", file: "keys/id_rsa_laptop.pub"},
]
}
- {
username: "user",
sshkeys:
[
{comment: "Desktop pc", file: "keys/id_rsa_desktop.pub"}
]
}
- name: Server elevated setups
hosts: servers
become_user: root
tasks:
- include_tasks: templates/sudoers-allow-service-management.yaml
vars:
user: user
servicename: caddy
servicefile: "/home/user/caddy/caddy.service"
The docker Ansible-maintained Docker Compose modules as of writing have no support for Docker Compose v2 or above. Hence currently a manual solution is used. If I find a good external module/solution, I'll hopefully implement that down the line. (In case you know of one, please feel free to open an Issue and let me know!)
Ansible is licensed under GNU GPLv3. You can view the full license on the Ansible GitHub repository.
These templates are released into the public domain through the Unlicense. You can view the LICENSE file in this repository here.