From c42ffc0edc34a8a120c60c38df75937090902e58 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Thu, 15 Aug 2019 07:27:57 +0000 Subject: [PATCH] Ansible nginx role using ansible-galaxy --- ansible/apt-up.yml | 17 +++++ ansible/hosts | 53 +++++++++++++++ ansible/nginx.yml | 6 ++ ansible/roles/nginx/README.md | 38 +++++++++++ ansible/roles/nginx/defaults/main.yml | 2 + ansible/roles/nginx/files/index.html | 25 +++++++ ansible/roles/nginx/files/nginx.conf | 88 +++++++++++++++++++++++++ ansible/roles/nginx/handlers/main.yml | 7 ++ ansible/roles/nginx/meta/main.yml | 53 +++++++++++++++ ansible/roles/nginx/service.yml | 3 + ansible/roles/nginx/tasks/configure.yml | 7 ++ ansible/roles/nginx/tasks/install.yml | 4 ++ ansible/roles/nginx/tasks/main.yml | 7 ++ ansible/roles/nginx/tests/inventory | 2 + ansible/roles/nginx/tests/test.yml | 5 ++ ansible/roles/nginx/vars/main.yml | 2 + 16 files changed, 319 insertions(+) create mode 100644 ansible/apt-up.yml create mode 100644 ansible/hosts create mode 100644 ansible/nginx.yml create mode 100644 ansible/roles/nginx/README.md create mode 100644 ansible/roles/nginx/defaults/main.yml create mode 100644 ansible/roles/nginx/files/index.html create mode 100644 ansible/roles/nginx/files/nginx.conf create mode 100644 ansible/roles/nginx/handlers/main.yml create mode 100644 ansible/roles/nginx/meta/main.yml create mode 100644 ansible/roles/nginx/service.yml create mode 100644 ansible/roles/nginx/tasks/configure.yml create mode 100644 ansible/roles/nginx/tasks/install.yml create mode 100644 ansible/roles/nginx/tasks/main.yml create mode 100644 ansible/roles/nginx/tests/inventory create mode 100644 ansible/roles/nginx/tests/test.yml create mode 100644 ansible/roles/nginx/vars/main.yml diff --git a/ansible/apt-up.yml b/ansible/apt-up.yml new file mode 100644 index 0000000..fe0bf17 --- /dev/null +++ b/ansible/apt-up.yml @@ -0,0 +1,17 @@ +--- +- hosts: all + become: yes + tasks: + - name: Ensure package lists are up-to-date + apt: + update_cache: yes + - name: Ensure packages are up-to-date + apt: + upgrade: dist + - name: Remove unused packages from the cache + apt: + autoclean: yes + - name: Remove dependencies that are no longer required + apt: + autoremove: yes + diff --git a/ansible/hosts b/ansible/hosts new file mode 100644 index 0000000..d27c2ca --- /dev/null +++ b/ansible/hosts @@ -0,0 +1,53 @@ +# This is the default ansible 'hosts' file. +# +# It should live in /etc/ansible/hosts +# +# - Comments begin with the '#' character +# - Blank lines are ignored +# - Groups of hosts are delimited by [header] elements +# - You can enter hostnames or ip addresses +# - A hostname/ip can be a member of multiple group +# Ex 1: Ungrouped hosts, specify before any group headers. + +[group] +www.domain.com +sub.domain.com:22 +0.0.0.0 +127.0.0.1:22 + +[othergroup] +sub.domain.com:22 +127.0.0.1:22 + +## green.example.com +## blue.example.com +## 192.168.100.1 +## 192.168.100.10 + +# Ex 2: A collection of hosts belonging to the 'webservers' group + +## [webservers] +## alpha.example.org +## beta.example.org +## 192.168.1.100 +## 192.168.1.110 + +# If you have multiple hosts following a pattern you can specify +# them like this: + +## www[001:006].example.com + +# Ex 3: A collection of database servers in the 'dbservers' group + +## [dbservers] +## +## db01.intranet.mydomain.net +## db02.intranet.mydomain.net +## 10.25.1.56 +## 10.25.1.57 + +# Here's another example of host ranges, this time there are no +# leading 0s: + +## db-[99:101]-node.example.com + diff --git a/ansible/nginx.yml b/ansible/nginx.yml new file mode 100644 index 0000000..221040c --- /dev/null +++ b/ansible/nginx.yml @@ -0,0 +1,6 @@ +--- +- hosts: nginx + become: yes + roles: + - nginx + - core diff --git a/ansible/roles/nginx/README.md b/ansible/roles/nginx/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/ansible/roles/nginx/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/ansible/roles/nginx/defaults/main.yml b/ansible/roles/nginx/defaults/main.yml new file mode 100644 index 0000000..4c1bb16 --- /dev/null +++ b/ansible/roles/nginx/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for /etc/ansible/roles/nginx \ No newline at end of file diff --git a/ansible/roles/nginx/files/index.html b/ansible/roles/nginx/files/index.html new file mode 100644 index 0000000..b0d878e --- /dev/null +++ b/ansible/roles/nginx/files/index.html @@ -0,0 +1,25 @@ + + + +Welcome to nginx! + + + +

Klips!

+

If you see this page, the nginx web server is successfully installed and +working. Further configuration is required.

+ +

For online documentation and support please refer to +nginx.org.
+Commercial support is available at +nginx.com.

+ +

Thank you for using nginx.

+ + diff --git a/ansible/roles/nginx/files/nginx.conf b/ansible/roles/nginx/files/nginx.conf new file mode 100644 index 0000000..1b86f41 --- /dev/null +++ b/ansible/roles/nginx/files/nginx.conf @@ -0,0 +1,88 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + + ## + # Basic Settings + ## + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + # server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + include /etc/nginx/mime.types; + +default_type application/octet-stream; + + ## + # SSL Settings + ## + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + ## + # Gzip Settings + ## + + gzip on; + gzip_disable "msie6"; + + # gzip_vary on; + # gzip_proxied any; + # gzip_comp_level 6; + # gzip_buffers 16 8k; + + + # gzip_http_version 1.1; + # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; + + ## + # Virtual Host Configs + ## + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} + + +#mail { +# # See sample authentication script at: +# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript +# +# # auth_http localhost/auth.php; +# # pop3_capabilities "TOP" "USER"; +# # imap_capabilities "IMAP4rev1" "UIDPLUS"; +# +# server { +# listen localhost:110; +# protocol pop3; +# proxy on; +# } +# +# server { +# listen localhost:143; +# protocol imap; +# proxy on; +# } +#} diff --git a/ansible/roles/nginx/handlers/main.yml b/ansible/roles/nginx/handlers/main.yml new file mode 100644 index 0000000..29d8e6a --- /dev/null +++ b/ansible/roles/nginx/handlers/main.yml @@ -0,0 +1,7 @@ +--- +# handlers file for /etc/ansible/roles/nginx +# + +- name: restart nginx + service: name=nginx state=restarted + diff --git a/ansible/roles/nginx/meta/main.yml b/ansible/roles/nginx/meta/main.yml new file mode 100644 index 0000000..faf862d --- /dev/null +++ b/ansible/roles/nginx/meta/main.yml @@ -0,0 +1,53 @@ +galaxy_info: + author: Shaun Reed + description: A template for nginx webserver + company: (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.4 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. + diff --git a/ansible/roles/nginx/service.yml b/ansible/roles/nginx/service.yml new file mode 100644 index 0000000..aefe3d6 --- /dev/null +++ b/ansible/roles/nginx/service.yml @@ -0,0 +1,3 @@ +--- +- name: Start and enable nginx service + service: name=nginx state=restarted enabled=yes diff --git a/ansible/roles/nginx/tasks/configure.yml b/ansible/roles/nginx/tasks/configure.yml new file mode 100644 index 0000000..c37d458 --- /dev/null +++ b/ansible/roles/nginx/tasks/configure.yml @@ -0,0 +1,7 @@ +--- +- name: Copy nginx configuration file + copy: src=files/nginx.conf dest=/etc/nginx/nginx.conf +- name: Copy index.html file + copy: src=files/index.html dest=/var/www/html + notify: + - restart nginx diff --git a/ansible/roles/nginx/tasks/install.yml b/ansible/roles/nginx/tasks/install.yml new file mode 100644 index 0000000..5ee5a69 --- /dev/null +++ b/ansible/roles/nginx/tasks/install.yml @@ -0,0 +1,4 @@ +--- +- name: Install nginx Package + apt: name=nginx state=latest + diff --git a/ansible/roles/nginx/tasks/main.yml b/ansible/roles/nginx/tasks/main.yml new file mode 100644 index 0000000..7ba00f2 --- /dev/null +++ b/ansible/roles/nginx/tasks/main.yml @@ -0,0 +1,7 @@ +--- +# tasks file for /etc/ansible/roles/nginx + +- import_tasks: install.yml +- import_tasks: configure.yml +- import_tasks: service.yml + diff --git a/ansible/roles/nginx/tests/inventory b/ansible/roles/nginx/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/ansible/roles/nginx/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/ansible/roles/nginx/tests/test.yml b/ansible/roles/nginx/tests/test.yml new file mode 100644 index 0000000..f53f9a6 --- /dev/null +++ b/ansible/roles/nginx/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - /etc/ansible/roles/nginx \ No newline at end of file diff --git a/ansible/roles/nginx/vars/main.yml b/ansible/roles/nginx/vars/main.yml new file mode 100644 index 0000000..e8addf9 --- /dev/null +++ b/ansible/roles/nginx/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for /etc/ansible/roles/nginx \ No newline at end of file