Add ansible role

main
Ruan Bekker 3 years ago
parent 588c3c3495
commit 38a062e252
  1. 1
      .gitignore
  2. 37
      Vagrantfile
  3. 1
      ansible/inventory
  4. 9
      ansible/playbook.yml
  5. 1
      ansible/roles/main/defaults/main.yml
  6. 8
      ansible/roles/main/tasks/main.yml
  7. 29
      ansible/roles/website/.travis.yml
  8. 38
      ansible/roles/website/README.md
  9. 21
      ansible/roles/website/defaults/main.yml
  10. 50
      ansible/roles/website/files/styles.css
  11. 15
      ansible/roles/website/handlers/main.yml
  12. 52
      ansible/roles/website/meta/main.yml
  13. 59
      ansible/roles/website/tasks/configuration.yml
  14. 13
      ansible/roles/website/tasks/main.yml
  15. 8
      ansible/roles/website/tasks/setup-ubuntu.yml
  16. 30
      ansible/roles/website/templates/app.conf.j2
  17. 29
      ansible/roles/website/templates/index.html.j2
  18. 37
      ansible/roles/website/templates/nginx.conf.j2
  19. 2
      ansible/roles/website/tests/inventory
  20. 5
      ansible/roles/website/tests/test.yml
  21. 2
      ansible/roles/website/vars/main.yml

1
.gitignore vendored

@ -0,0 +1 @@
.vagrant/*

37
Vagrantfile vendored

@ -0,0 +1,37 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.hostname = "sektor"
config.vm.define "sektor"
config.vagrant.plugins = ['vagrant-vbguest']
config.vm.network "private_network", ip: "192.168.33.23"
config.vm.synced_folder "./", "/home/vagrant/project"
config.vm.provider "virtualbox" do |vb|
vb.cpus = 2
vb.memory = "2048"
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--ioapic", "on"]
end
config.vm.provision "shell", inline: <<-SHELL
apt update
apt install curl git cmake vim -y
SHELL
config.vm.provision "docker" do |d|
d.run "nginx", image: "nginx:stable",
args: "-p 8080:80"
end
# Ansible provisioner
config.vm.provision "ansible" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = "ansible/playbook.yml"
ansible.inventory_path = "ansible/inventory"
ansible.become = true
end
end

@ -0,0 +1 @@
sektor ansible_host=192.168.33.23

@ -0,0 +1,9 @@
---
- name: my-playbook
hosts: sektor
become: yes
become_user: root
roles:
- { role: ./roles/website }

@ -0,0 +1,8 @@
- name: Install Promtail Dependencies
apt:
name: "{{ item }}"
state: latest
update_cache: yes
with_items:
- tar
- unzip

@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

@ -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).

@ -0,0 +1,21 @@
---
# defaults file for website
nginx_remove_default_vhost: true
nginx_default_vhost_path: /etc/nginx/sites-enabled/default
nginx_vhost_path: /etc/nginx/sites-enabled
nginx_conf_path: /etc/nginx/conf.d
nginx_log_path: /var/log/nginx
nginx_access_log_filename: access
nginx_error_log_filename: error
nginx_server_name: "_"
nginx_user: "www-data"
nginx_web_root: "/var/www/app"
root_group: "root"
webpage_title: "hello world"
webpage_text: "homepage"
webpage_url: "https://ruan.dev"
access_log_args: "main buffer=16k flush=2m"
nginx_log_format: |-
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'

@ -0,0 +1,50 @@
html, body {
background-color: #fff;
color: #636b6f;
font-family: 'Nunito', sans-serif;
font-weight: 200;
height: 100vh;
margin: 0;
}
.full-height {
height: 100vh;
}
.flex-center {
align-items: center;
display: flex;
justify-content: center;
}
.position-ref {
position: relative;
}
.top-right {
position: absolute;
right: 10px;
top: 18px;
}
.content {
text-align: center;
}
.title {
font-size: 84px;
}
.links > a {
color: #636b6f;
padding: 0 25px;
font-size: 13px;
font-weight: 600;
letter-spacing: .1rem;
text-decoration: none;
text-transform: uppercase;
}
.m-b-md {
margin-bottom: 30px;
}

@ -0,0 +1,15 @@
---
# handlers file for website
- name: restart nginx
service:
name: nginx
state: restarted
- name: validate nginx configuration
command: nginx -t -c /etc/nginx/nginx.conf
changed_when: false
- name: reload nginx
service:
name: nginx
state: reloaded

@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your 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.1
# 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.

@ -0,0 +1,59 @@
---
- name: Copy nginx configuration in place.
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
owner: root
group: "{{ root_group }}"
mode: 0644
notify:
- reload nginx
- name: Remove default nginx vhost config file (if configured).
file:
path: "{{ nginx_default_vhost_path }}"
state: absent
when: nginx_remove_default_vhost | bool
notify: restart nginx
- name: Ensure nginx_web_root exists.
file:
path: "{{ nginx_web_root }}"
state: directory
mode: 0755
notify: reload nginx
- name: Ensure nginx_web_root exists.
file:
path: "{{ nginx_web_root }}"
state: directory
mode: 0755
notify: reload nginx
- name: copy promtail systemd unit
copy:
src: styles.css
dest: "{{ nginx_web_root }}/styles.css"
owner: root
group: "{{ root_group }}"
mode: 0644
notify: reload nginx
- name: Add website files
template:
src: index.html.j2
dest: "{{ nginx_web_root }}/index.html"
owner: root
group: "{{ root_group }}"
mode: 0644
notify: reload nginx
- name: Add managed vhost config files.
template:
src: app.conf.j2
dest: "{{ nginx_conf_path }}/app.conf"
force: true
owner: root
group: "{{ root_group }}"
mode: 0644
notify: reload nginx

@ -0,0 +1,13 @@
---
# tasks file for website
- include_tasks: setup-ubuntu.yml
when: ansible_distribution == 'Ubuntu'
# vhost configuration.
- import_tasks: configuration.yml
- name: Ensure nginx service is running as configured.
service:
name: nginx
state: started
enabled: true

@ -0,0 +1,8 @@
---
- name: Ensure dirmngr and nginx is installed
apt:
name: "{{ item }}"
state: present
with_items:
- dirmngr
- nginx

@ -0,0 +1,30 @@
server {
listen 80;
server_name {{ nginx_server_name }};
root {{ nginx_web_root }};
index index.html;
charset utf-8;
location / {
try_files $uri $uri/ /index.html$is_args$args;
}
location = /favicon.ico {
access_log off;
log_not_found off;
}
location = /robots.txt {
access_log off;
log_not_found off;
}
location ~ /\.(?!well-known).* {
deny all;
}
location ~ /\.ht {
deny all;
}
}

@ -0,0 +1,29 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ webpage_title }}</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito:200,600" rel="stylesheet">
<!-- Styles -->
<link href="styles.css" rel="stylesheet">
</head>
<body>
<div class="flex-center position-ref full-height">
<div class="content">
<div class="title m-b-md">
{{ webpage_title }}
</div>
<div class="links">
<a href="{{ webpage_url }}">{{ webpage_text }}</a>
</div>
</div>
</div>
</body>
</html>

@ -0,0 +1,37 @@
user {{ nginx_user }};
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
# Basic Settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# SSL Settings
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
# Logging Settings
log_format main {{ nginx_log_format|indent(23) }};
access_log {{ nginx_log_path }}/{{ nginx_access_log_filename }}.log {{ access_log_args }};
error_log {{ nginx_log_path }}/{{ nginx_error_log_filename }}.log;
# Gzip Settings
gzip on;
# Virtual Host Configs
include {{ nginx_conf_path }}/*.conf;
}

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- website

@ -0,0 +1,2 @@
---
# vars file for website
Loading…
Cancel
Save