Ansible/Galaxy
From charlesreid1
Ansible Galaxy is a web community for exchanging Ansible resources.
Link: https://galaxy.ansible.com
Guide: https://galaxy.ansible.com/docs/finding/search.html
Contents
Examples
Nginx example
Let's look at the nginx example here: https://galaxy.ansible.com/geerlingguy/nginx
The user sets default values for variables using the default YAML file defaults/main.yml
default variable values
The default variable values are set in defaults/main.yml
.
The variables to be set by the user include:
- User provides virtual hosts (sites available) either through the YAML file (if short and easy), or by hand (if virtual hosts list is empty)
- Upstreams (if using nginx as a loadbalancer)
- nginx user to use
- worker processes, worker connections, multi accept
- Error/access logs
- Timeout times
- Etc etc etc.
Some ways of customizing the nginx file from this YAML file:
- nginx_extra_http_options - Extra lines to be inserted in the top-level http block in nginx.conf
- nginx_extra_conf_options - Extra lines to be inserted in the top of nginx.conf
To override the names of the template files used, add the following to the default variables file:
nginx_conf_template: "nginx.conf.j2" nginx_vhost_template: "vhost.j2"
templates
The nginx config file (which uses the variables set in the defaults YAML file above) lives in the templates folder, in templates/nginx.conf.j2
.
To override the names of the template files used, add the following to the default variables file:
nginx_conf_template: "nginx.conf.j2" nginx_vhost_template: "vhost.j2"
To set it per virtual host, do something like this:
nginx_vhosts: - listen: "80 default_server" server_name: "site1.example.com" root: "/var/www/site1.example.com" index: "index.php index.html index.htm" template: "{{ playbook_dir }}/templates/site1.example.com.vhost.j2" - server_name: "site2.example.com" root: "/var/www/site2.example.com" index: "index.php index.html index.htm" template: "{{ playbook_dir }}/templates/site2.example.com.vhost.j2"
Example Playbook
- hosts: server roles: - { role: geerlingguy.nginx }
Flags