Ansible/Galaxy: Difference between revisions
From charlesreid1
(Created page with "Ansible Galaxy is a web community for exchanging Ansible resources.") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
Ansible Galaxy is a web community for exchanging Ansible resources. | Ansible Galaxy is a web community for exchanging Ansible resources. | ||
Link: https://galaxy.ansible.com | |||
Guide: https://galaxy.ansible.com/docs/finding/search.html | |||
=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 <code>defaults/main.yml</code> | |||
===default variable values=== | |||
The default variable values are set in <code>defaults/main.yml</code>. | |||
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: | |||
<pre> | |||
nginx_conf_template: "nginx.conf.j2" | |||
nginx_vhost_template: "vhost.j2" | |||
</pre> | |||
===templates=== | |||
The nginx config file (which uses the variables set in the defaults YAML file above) lives in the templates folder, in <code>templates/nginx.conf.j2</code>. | |||
To override the names of the template files used, add the following to the default variables file: | |||
<pre> | |||
nginx_conf_template: "nginx.conf.j2" | |||
nginx_vhost_template: "vhost.j2" | |||
</pre> | |||
To set it per virtual host, do something like this: | |||
<pre> | |||
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" | |||
</pre> | |||
=Example Playbook= | |||
<pre> | |||
- hosts: server | |||
roles: | |||
- { role: geerlingguy.nginx } | |||
</pre> | |||
=Flags= | |||
{{AnsibleFlag}} | |||
Latest revision as of 01:34, 15 November 2018
Ansible Galaxy is a web community for exchanging Ansible resources.
Link: https://galaxy.ansible.com
Guide: https://galaxy.ansible.com/docs/finding/search.html
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