diff --git a/mariadb/playbook.yml b/mariadb/playbook.yml new file mode 100755 index 0000000..5a9fc8c --- /dev/null +++ b/mariadb/playbook.yml @@ -0,0 +1,29 @@ +################################################# +# DO Community Playbooks: Docker +################################################# +--- +- hosts: all + become: true + vars_files: + - vars/default.yml + + tasks: + - name: Pull default Mariadb image + docker_image: + name: "{{ image_name }}" + source: pull + state: present + + # Creates the number of containers defined by the variable create_containers, using values from vars file + - name: Create Mariadb container + docker_container: + name: "{{ container_name }}" + image: "{{ image_name }}" + state: started + restart_policy: "unless-stopped" + env: + MARIADB_ROOT_PASSWORD: "{{ db_password }}" + published_ports: + - 3306:3306 + volumes: + - "{{ data_location }}:/var/lib/mysql" diff --git a/mariadb/readme.md b/mariadb/readme.md new file mode 100644 index 0000000..f6d7ecc --- /dev/null +++ b/mariadb/readme.md @@ -0,0 +1,46 @@ +# Docker on Ubuntu 18.04 + +This playbook will install Docker an Ubuntu 18.04 machine, as explained in the guide on +[How to Use Ansible to Install and Set Up Docker on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-use-ansible-to-install-and-set-up-docker-on-ubuntu-18-04). +A number of containers will be created with the options specified in the `vars/default.yml` variable file. + +## Settings + +- `create_containers`: number of containers to create. +- `default_container_name`: default name for new containers. +- `default_container_image`: default image for new containers. +- `default_container_command`: default command to run on new containers. + + +## Running this Playbook + +Quick Steps: + +### 1. Obtain the playbook +```shell +git clone https://github.com/do-community/ansible-playbooks.git +cd ansible-playbooks/docker_ubuntu1804 +``` + +### 2. Customize Options + +```shell +nano vars/default.yml +``` + +```yml +#vars/default.yml +--- +create_containers: 4 +default_container_name: docker +default_container_image: ubuntu +default_container_command: sleep 1d +``` + +### 3. Run the Playbook + +```command +ansible-playbook -l [target] -i [inventory file] -u [remote user] playbook.yml +``` + +For more information on how to run this Ansible setup, please check this guide: [How to Use Ansible to Install and Set Up Docker on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-use-ansible-to-install-and-set-up-docker-on-ubuntu-18-04). \ No newline at end of file diff --git a/mariadb/vars/default.yml b/mariadb/vars/default.yml new file mode 100644 index 0000000..90cdc16 --- /dev/null +++ b/mariadb/vars/default.yml @@ -0,0 +1,6 @@ +--- +container_name: mariadb +image_name: mariadb:latest +db_password: '123456' +data_location: /var/lib/mariadb/data + diff --git a/wordpress/files/nginx.conf-ff.j2 b/wordpress/files/nginx.conf-ff.j2 new file mode 100644 index 0000000..f1f48cf --- /dev/null +++ b/wordpress/files/nginx.conf-ff.j2 @@ -0,0 +1,21 @@ +server { + + listen 80; + server_name {{ http_host }}; + + # Allow large attachments + client_max_body_size 128M; + + location / { + + proxy_set_header Host $host:$server_port; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Scheme $scheme; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Real-IP $remote_addr; + add_header Strict-Transport-Security "max-age=15552000; includeSubDomains" always; + proxy_pass http://localhost:{{ web_port }}; + } + +} + diff --git a/wordpress/files/nginx.conf.j2 b/wordpress/files/nginx.conf.j2 new file mode 100644 index 0000000..21a22d5 --- /dev/null +++ b/wordpress/files/nginx.conf.j2 @@ -0,0 +1,20 @@ +server { + + listen 80; + server_name {{ http_host }}; + + # Allow large attachments + client_max_body_size 128M; + + + location / { + proxy_read_timeout 90; + proxy_connect_timeout 90; + proxy_redirect off; + proxy_pass http://localhost:{{ web_port }}; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/wordpress/nginx.conf b/wordpress/nginx.conf new file mode 100644 index 0000000..0f9efbb --- /dev/null +++ b/wordpress/nginx.conf @@ -0,0 +1,86 @@ +user www-data; +worker_processes auto; +pid /run/nginx.pid; +include /etc/nginx/modules-enabled/*.conf; + +events { + worker_connections 768; + # multi_accept on; +} + +http { + +log_format scripts '$document_root$fastcgi_script_name > $request @ $fastcgi_path_info'; + ## + # 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 TLSv1.3; # 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_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/wordpress/playbook-ff.yml b/wordpress/playbook-ff.yml new file mode 100755 index 0000000..7152eb4 --- /dev/null +++ b/wordpress/playbook-ff.yml @@ -0,0 +1,83 @@ +################################################# +# DO Community Playbooks: Docker +################################################# +--- +- hosts: all + become: true + vars_files: + - vars/default.yml + + tasks: + - name: Pull Wordpress image + docker_image: + name: "{{ image_name }}" + source: pull + force_source: yes + + - name: Copy dockerfile + synchronize: src=web dest=/tmp + + - name: Build nginx webserver image + docker_image: + name: wordpress-web + build: + path: /tmp/web/ + dockerfile: /tmp/web/Dockerfile + pull: yes + state: present + source: build + + - name: Create Wordpress container + docker_container: + name: "{{ container_name }}" + image: "{{ image_name }}" + state: started + restart_policy: "unless-stopped" + env: + WORDPRESS_DB_HOST: "{{ db_host }}" + WORDPRESS_DB_USER: "{{ db_user }}" + WORDPRESS_DB_PASSWORD: "{{ db_pass }}" + WORDPRESS_DB_NAME: "{{ db_name }}" + volumes: + - "/var/lib/{{ http_host }}:/var/www/html" + + - name: Create webserver container + docker_container: + name: wp-web + image: wordpress-web + state: started + restart_policy: "unless-stopped" + links: + - "{{ container_name }}:wordpress" + published_ports: + - "127.0.0.1:{{ web_port }}:80" + volumes: + - "/var/lib/{{ http_host }}:/var/www/html" + +# - name: Check if Nginx conf file exists +# stat: path="/etc/nginx/sites-available/{{ http_conf }}" +# register: status + +# - name: No need to reload Nginx +# debug: msg= {{ "No need to reload Nginx as sites-available entries have already been created" }} + + - name: Set Nginx conf file +# when: status.stat.exists == false + template: + src: "files/nginx.conf-ff.j2" + dest: "/etc/nginx/sites-available/{{ http_conf }}" + + - name: Enable new site +# when: status.stat.exists == false + file: + src: "/etc/nginx/sites-available/{{ http_conf }}" + dest: "/etc/nginx/sites-enabled/{{ http_conf }}" + state: link + notify: Reload Nginx + + handlers: + - name: Reload Nginx + service: + name: nginx + state: reloaded + diff --git a/wordpress/playbook.yml b/wordpress/playbook.yml new file mode 100755 index 0000000..3ba4f7f --- /dev/null +++ b/wordpress/playbook.yml @@ -0,0 +1,69 @@ +################################################# +# DO Community Playbooks: Docker +################################################# +--- +- hosts: all + become: true + vars_files: + - vars/default.yml + + tasks: + - name: Pull Wordpress image + docker_image: + name: "{{ image_name }}" + source: pull + force_source: yes + + - name: Ensure SSH Directory exists + file: + path: "/var/lib/{{ http_host }}" + state: directory + group: www-data + owner: www-data + mode: 0700 + + - name: Create Wordpress container + docker_container: + name: "{{ container_name }}" + image: "{{ image_name }}" + state: started + restart_policy: "unless-stopped" + env: + WORDPRESS_DB_HOST: "{{ db_host }}" + WORDPRESS_DB_USER: "{{ db_user }}" + WORDPRESS_DB_PASSWORD: "{{ db_pass }}" + WORDPRESS_DB_NAME: "{{ db_name }}" + links: + - "mariadb:db" + published_ports: + - "127.0.0.1:{{ web_port }}:80" + volumes: + - "/var/lib/{{ http_host }}:/var/www/html" + + - name: Check if Nginx conf file exists + stat: path="/etc/nginx/sites-available/{{ http_conf }}" + register: status + + - name: No need to reload Nginx + debug: msg= {{ "No need to reload Nginx as sites-available entries have already been created" }} + + - name: Set Nginx conf file + when: status.stat.exists == false + template: + src: "files/nginx.conf.j2" + dest: "/etc/nginx/sites-available/{{ http_conf }}" + + - name: Enable new site + when: status.stat.exists == false + file: + src: "/etc/nginx/sites-available/{{ http_conf }}" + dest: "/etc/nginx/sites-enabled/{{ http_conf }}" + state: link + notify: Reload Nginx + + handlers: + - name: Reload Nginx + service: + name: nginx + state: reloaded + diff --git a/wordpress/readme.md b/wordpress/readme.md new file mode 100644 index 0000000..f6d7ecc --- /dev/null +++ b/wordpress/readme.md @@ -0,0 +1,46 @@ +# Docker on Ubuntu 18.04 + +This playbook will install Docker an Ubuntu 18.04 machine, as explained in the guide on +[How to Use Ansible to Install and Set Up Docker on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-use-ansible-to-install-and-set-up-docker-on-ubuntu-18-04). +A number of containers will be created with the options specified in the `vars/default.yml` variable file. + +## Settings + +- `create_containers`: number of containers to create. +- `default_container_name`: default name for new containers. +- `default_container_image`: default image for new containers. +- `default_container_command`: default command to run on new containers. + + +## Running this Playbook + +Quick Steps: + +### 1. Obtain the playbook +```shell +git clone https://github.com/do-community/ansible-playbooks.git +cd ansible-playbooks/docker_ubuntu1804 +``` + +### 2. Customize Options + +```shell +nano vars/default.yml +``` + +```yml +#vars/default.yml +--- +create_containers: 4 +default_container_name: docker +default_container_image: ubuntu +default_container_command: sleep 1d +``` + +### 3. Run the Playbook + +```command +ansible-playbook -l [target] -i [inventory file] -u [remote user] playbook.yml +``` + +For more information on how to run this Ansible setup, please check this guide: [How to Use Ansible to Install and Set Up Docker on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-use-ansible-to-install-and-set-up-docker-on-ubuntu-18-04). \ No newline at end of file diff --git a/wordpress/vars/default.yml b/wordpress/vars/default.yml new file mode 100644 index 0000000..223b042 --- /dev/null +++ b/wordpress/vars/default.yml @@ -0,0 +1,13 @@ +--- +http_host: "menus.greatbear.in" +http_conf: "menus.greatbear.in.conf" + +container_name: menu-chd +image_name: wordpress:latest + +db_name: "menu_chd" +db_user: "root" +db_pass: "123456" +db_host: "db" + +web_port: "9180" diff --git a/wordpress/web/Dockerfile b/wordpress/web/Dockerfile new file mode 100644 index 0000000..9e620af --- /dev/null +++ b/wordpress/web/Dockerfile @@ -0,0 +1,3 @@ +FROM nginx:alpine + +COPY nginx.conf /etc/nginx/nginx.conf diff --git a/wordpress/web/nginx.conf b/wordpress/web/nginx.conf new file mode 100644 index 0000000..8ba6af4 --- /dev/null +++ b/wordpress/web/nginx.conf @@ -0,0 +1,83 @@ +worker_processes auto; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + #tcp_nopush on; + + keepalive_timeout 65; + + set_real_ip_from 10.0.0.0/8; + set_real_ip_from 172.16.0.0/12; + set_real_ip_from 192.168.0.0/16; + real_ip_header X-Real-IP; + + #gzip on; + + upstream php-handler { + server wordpress:9000; + } + + server { + listen 80; + listen [::]:80; + + index index.php index.html index.htm; + + root /var/www/html; + + location ~ /.well-known/acme-challenge { + allow all; + root /var/www/html; + } + + location / { + try_files $uri $uri/ /index.php$is_args$args; + } + + location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass php-handler; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } + + location ~ /\.ht { + deny all; + } + + location = /favicon.ico { + log_not_found off; access_log off; + } + location = /robots.txt { + log_not_found off; access_log off; allow all; + } + location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ { + expires max; + log_not_found off; + } + + # set max upload size + client_max_body_size 10G; + } +}