Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #150912: Added role to deploy Joomla #23

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,70 @@
# Automating Common IT Infra Tasks
Repo that contains scripts to automate various infrastructure activities like developer workstation setup and configuration.

Repo that contains scripts to automate various infrastructure activities like developer workstation setup and configuration.



## Setting up User Workstations

User workstations can be set up with the required development tools by running the following command in a terminal. Needs to be run by a user with sudo access. Script is tested to work on Ubuntu 16.04 & 14.04 although it might work with newer versions too.



```bash

sudo mkdir -p /tmp/ansible-ttpl-it-automation && sudo wget -q "https://raw.githubusercontent.com/techjoomla/infra-automation/master/ttpl_install.sh" -O /tmp/ansible-ttpl-it-automation/ttpl_install.sh && sudo chmod +x /tmp/ansible-ttpl-it-automation/ttpl_install.sh && sudo /tmp/ansible-ttpl-it-automation/ttpl_install.sh

```

The script will set up all the tools defined in the `environment-setup.yml` file and also set up 2 vhosts, one each for PHP5 & PHP7

- To access the PHP5 localhost, navigate to http://machineusername-php5.local/ Eg: http://ttpl21-php5.local/
- To access the PHP7 localhost, navigate to http://machineusername-php7.local/ Eg: http://ttpl21-php7.local/


- To access the PHP5 localhost, navigate to http://machineusername-php5.local/ Eg: http://ttpl21-php5.local/

- To access the PHP7 localhost, navigate to http://machineusername-php7.local/ Eg: http://ttpl21-php7.local/

- The files for this are present in /var/www/ttpl21-php5.local/public or in /var/www/ttpl21-php7.local/public

- PHP My Admin is not installed, so you can download Adminer (http://adminer.org/) and place the file anywhere in your local



## Joomla site CI CD
1. Create folder `secret` alongside joomla.yml to store your server encrypted details (using ansible vault)

```javascript
joomla_user: "username" # Username to connect your host through ssh
joomla_password: "password" # Password to connect your host through ssh
joomla_db: "MYDB" # Database
joomla_host: "localhost" # Database host
joomla_dbprefix: "z467w_" # Table prefix
joomla_smtpuser: "" # SMTP Username
joomla_smtppass: "" # SMTP Password
joomla_smtphost: "localhost" # SMTP Host
```

2. Create folder `inventory` alongside joomla.yml to store your server details and Joomla configurations

E.g:
file: inventory/myserver
```javascript

[mysitegroup]
YOUR_SERVER_IP ansible_host=YOUR_SERVER_HOST ansible_user={{joomla_user}} ansible_ssh_private_key_file=SSH_KEY_PATH

[mysitegroup:vars]
doc_root=/home/{{joomla_user}}/public_html # PATH to deploy Joomla files
site_id=myserver # Name of secret file
deploy_env_domain=example.com # Site domain e.g example.com
server_runs_as=www-data # Server user
server_runs_as_group=www-data # Group of files
joomla_sitename="core Site" # Overridden site name
joomla_log_path="/home/USER_NAME/public_html/logs" # Log path
joomla_tmp_path="/home/USER_NAME/public_html/tmp" # Tmp folder path
```

### Run playbook
```bash
ansible-playbook -i inventory/myserver joomla.yml --vault-password-file=PATH_OF_VAULT_PASSWORD_FILE
```
8 changes: 8 additions & 0 deletions joomla.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- hosts: all
become: false
vars:
workspace: "{{ lookup('env','WORKSPACE') }}"
vars_files: ["secrets/{{site_id}}"]
roles:
- joomla
90 changes: 90 additions & 0 deletions roles/joomla/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
server_runs_as: "www-data"
server_runs_as_group: "www-data"

# Joomla config variable
joomla_offline : "0"
joomla_offline_message : "This site is down for maintenance.<br />Please check back again soon."
joomla_display_offline_message : "1"
joomla_offline_image : ""
joomla_sitename : ""
joomla_editor : "tinymce"
joomla_captcha : "0"
joomla_list_limit : "20"
joomla_access : "1"
joomla_debug : "0"
joomla_debug_lang : "0"
joomla_dbtype : "mysqli"
joomla_live_site : ""
joomla_secret : ""
joomla_gzip : "0"
joomla_error_reporting : "none"
joomla_helpurl : "https://help.joomla.org/proxy/index.php?keyref:Help{major}{minor}:{keyref}"
joomla_ftp_host : "127.0.0.1"
joomla_ftp_port : "21"
joomla_ftp_user : ""
joomla_ftp_pass : ""
joomla_ftp_root : ""
joomla_ftp_enable : "0"
joomla_offset : "UTC"
joomla_mailonline : "1"
joomla_mailer : "mail"
joomla_mailfrom : ""
joomla_fromname : ""
joomla_sendmail : "/usr/sbin/sendmail"
joomla_smtpauth : "0"
joomla_smtpsecure : "none"
joomla_smtpport : "25"
joomla_caching : "0"
joomla_cache_handler : "file"
joomla_cachetime : "15"
joomla_cache_platformprefix : "0"
joomla_MetaDesc : ""
joomla_MetaKeys : ""
joomla_MetaTitle : "1"
joomla_MetaAuthor : "1"
joomla_MetaVersion : "0"
joomla_robots : "noindex, nofollow"
joomla_sef : "1"
joomla_sef_rewrite : "0"
joomla_sef_suffix : "0"
joomla_unicodeslugs : "0"
joomla_feed_limit : "10"
joomla_feed_email : "none"
joomla_log_path : ""
joomla_tmp_path : ""
joomla_lifetime : "180"
joomla_session_handler : "database"
joomla_memcache_persist : "1"
joomla_memcache_compress : "0"
joomla_memcache_server_host : "localhost"
joomla_memcache_server_port : "11211"
joomla_memcached_persist : "1"
joomla_memcached_compress : "0"
joomla_memcached_server_host : "localhost"
joomla_memcached_server_port : "11211"
joomla_redis_persist : "1"
joomla_redis_server_host : "localhost"
joomla_redis_server_port : "6379"
joomla_redis_server_auth : ""
joomla_redis_server_db : "0"
joomla_proxy_enable : "0"
joomla_proxy_host : ""
joomla_proxy_port : ""
joomla_proxy_user : ""
joomla_proxy_pass : ""
joomla_massmailoff : "0"
joomla_MetaRights : ""
joomla_sitename_pagetitles : "0"
joomla_force_ssl : "2"
joomla_session_memcache_server_host : "localhost"
joomla_session_memcache_server_port : "11211"
joomla_session_memcached_server_host : "localhost"
joomla_session_memcached_server_port : "11211"
joomla_frontediting : "1"
joomla_cookie_domain : ""
joomla_cookie_path : ""
joomla_asset_id : "1"

# Cron list
cron_list: []
76 changes: 76 additions & 0 deletions roles/joomla/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
- name: Create configuration.php
template:
src: "roles/joomla/templates/configuration.php.j2"
dest: "{{ doc_root }}/configuration.php"
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"

- name: Create .htversion file
file:
path: "{{ doc_root }}/.htversion"
state: touch
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"

- name: Write commit number .htversion to file
shell: echo "{{ lookup('env','BUILD_NUMBER') }}" > {{ doc_root }}/.htversion

- name: Delete directories
file:
path: "{{ item.dest }}"
state: absent
with_items:
- {dest: '{{ doc_root }}/components'}
- {dest: '{{ doc_root }}/libraries'}
- {dest: '{{ doc_root }}/modules'}
- {dest: '{{ doc_root }}/plugins'}
- {dest: '{{ doc_root }}/language'}
- {dest: '{{ doc_root }}/cli'}
- {dest: '{{ doc_root }}/includes'}
- {dest: '{{ doc_root }}/layouts'}
- {dest: '{{ doc_root }}/templates'}
- {dest: '{{ doc_root }}/scripts'}
- {dest: '{{ doc_root }}/vendor'}
- {dest: '{{ doc_root }}/composer.json'}
- {dest: '{{ doc_root }}/composer.lock'}

- name: Create required directories
file:
path: "{{ item.dest }}"
state: directory
with_items:
- {dest: '{{ doc_root }}/cache'}
- {dest: '{{ doc_root }}/tmp'}
- {dest: '{{ doc_root }}/logs'}
- {dest: '{{ doc_root }}/administrator'}
- {dest: '{{ doc_root }}/administrator/cache'}

- name: create empty index.html files
file: path="{{ doc_root }}/{{ item }}/index.html" state=touch owner="{{server_runs_as}}" group="{{server_runs_as_group}}"
with_items:
- "cache"
- "tmp"
- "logs"
- "administrator/cache"

- name: Unarchive artifact on remote server
unarchive:
src: "{{ workspace | default('') }}/{{ artifact_filename }}"
dest: "{{ doc_root }}"
copy: yes
owner: "{{ server_runs_as }}"
group: "{{ server_runs_as_group }}"

- name: Create all wget cronjobs
become: false
tags: cron
cron:
name: "{{item.name}}"
minute: "{{item.minute}}"
hour: "{{item.hour}}"
job: "/usr/bin/wget --no-check-certificate -qO- '{{item.url}}' &> /dev/null"
with_items: "{{ cron_list }}"

- name: Run composer.json to install extensions if any
shell: cd {{ doc_root }} && composer install
when: "{{ run_composer|default(false) }}"
92 changes: 92 additions & 0 deletions roles/joomla/templates/configuration.php.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
class JConfig {
public $offline = '{{ joomla_offline | default(0) }}';
public $offline_message = '{{ joomla_offline_message | default("This site is down for maintenance. Please check back again soon") }}';
public $display_offline_message = '{{ joomla_display_offline_message| default(1) }}';
public $offline_image = '{{ joomla_offline_image| default("") }}';
public $sitename = '{{ joomla_sitename| default("Development version for tne new Joomla-based DPE site.") }}';
public $editor = '{{ joomla_editor| default("codemirror") }}';
public $captcha = '{{ joomla_captcha| default(0) }}';
public $list_limit = '{{ joomla_list_limit| default(20) }}';
public $access = '{{ joomla_access| default(1) }}';
public $debug = '{{ joomla_debug| default(0) }}';
public $debug_lang = '{{ joomla_debug_lang| default(0) }}';
public $dbtype = '{{ joomla_dbtype| default("mysqli") }}';
public $host = '{{ joomla_host| default("localhost") }}';
public $user = '{{ joomla_user| default("") }}';
public $password = '{{ joomla_password| default("") }}';
public $db = '{{ joomla_db| default("") }}';
public $dbprefix = '{{ joomla_dbprefix| default("") }}';
public $live_site = '{{ joomla_live_site| default("") }}';
public $secret = '{{ joomla_secret| default("") }}';
public $gzip = '{{ joomla_gzip| default(0) }}';
public $error_reporting = '{{ joomla_error_reporting| default("default") }}';
public $helpurl = '{{ joomla_helpurl| default("") }}';
public $ftp_host = '{{ joomla_ftp_host| default("") }}';
public $ftp_port = '{{ joomla_ftp_port| default("") }}';
public $ftp_user = '{{ joomla_ftp_user| default("") }}';
public $ftp_pass = '{{ joomla_ftp_pass| default("") }}';
public $ftp_root = '{{ joomla_ftp_root| default("") }}';
public $ftp_enable = '{{ joomla_ftp_enable| default(0) }}';
public $offset = '{{ joomla_offset| default("UTC") }}';
public $mailonline = '{{ joomla_mailonline| default(0) }}';
public $mailer = '{{ joomla_mailer| default("smtp") }}';
public $mailfrom = '{{ joomla_mailfrom| default("") }}';
public $fromname = '{{ joomla_fromname| default("") }}';
public $sendmail = '{{ joomla_sendmail| default("") }}';
public $smtpauth = '{{ joomla_smtpauth| default("") }}';
public $smtpuser = '{{ joomla_smtpuser| default("") }}';
public $smtppass = '{{ joomla_smtppass| default("") }}';
public $smtphost = '{{ joomla_smtphost| default("") }}';
public $smtpsecure = '{{ joomla_smtpsecure| default("") }}';
public $smtpport = '{{ joomla_smtpport| default("") }}';
public $caching = '{{ joomla_caching| default(0) }}';
public $cache_handler = '{{ joomla_cache_handler| default("file") }}';
public $cachetime = '{{ joomla_cachetime| default(100) }}';
public $MetaDesc = '{{ joomla_MetaDesc| default("") }}';
public $MetaKeys = '{{ joomla_MetaKeys| default("") }}';
public $MetaTitle = '{{ joomla_MetaTitle| default(1) }}';
public $MetaAuthor = '{{ joomla_MetaAuthor| default(1) }}';
public $MetaVersion = '{{ joomla_MetaVersion| default(0) }}';
public $robots = '{{ joomla_robots| default("noindex, nofollow") }}';
public $sef = '{{ joomla_sef| default(1) }}';
public $sef_rewrite = '{{ joomla_sef_rewrite| default(0) }}';
public $sef_suffix = '{{ joomla_sef_suffix| default(0) }}';
public $unicodeslugs = '{{ joomla_unicodeslugs| default(0) }}';
public $feed_limit = '{{ joomla_feed_limit| default(10) }}';
public $log_path = '{{ joomla_log_path| default("") }}';
public $tmp_path = '{{ joomla_tmp_path| default("") }}';
public $lifetime = '{{ joomla_lifetime| default(6000) }}';
public $session_handler = '{{ joomla_session_handler| default("database") }}';
public $memcache_persist = '{{ joomla_memcache_persist| default(1) }}';
public $memcache_compress = '{{ joomla_memcache_compress| default(0) }}';
public $memcache_server_host = '{{ joomla_memcache_server_host| default("localhost") }}';
public $memcache_server_port = '{{ joomla_memcache_server_port| default(11211) }}';
public $memcached_persist = '{{ joomla_memcached_persist| default(1) }}';
public $memcached_compress = '{{ joomla_memcached_compress| default(0) }}';
public $memcached_server_host = '{{ joomla_memcached_server_host| default("localhost") }}';
public $memcached_server_port = '{{ joomla_memcached_server_port| default(11211) }}';
public $redis_persist = '{{ joomla_redis_persist| default(1) }}';
public $redis_server_host = '{{ joomla_redis_server_host| default("localhost") }}';
public $redis_server_port = '{{ joomla_redis_server_port| default(6379) }}';
public $redis_server_auth = '{{ joomla_redis_server_auth| default("") }}';
public $redis_server_db = '{{ joomla_redis_server_db| default(0) }}';
public $proxy_enable = '{{ joomla_proxy_enable| default(0) }}';
public $proxy_host = '{{ joomla_proxy_host| default("") }}';
public $proxy_port = '{{ joomla_proxy_port| default("") }}';
public $proxy_user = '{{ joomla_proxy_user| default("") }}';
public $proxy_pass = '{{ joomla_proxy_pass| default("") }}';
public $massmailoff = '{{ joomla_massmailoff| default(1) }}';
public $MetaRights = '{{ joomla_MetaRights| default("") }}';
public $sitename_pagetitles = '{{ joomla_sitename_pagetitles| default(0) }}';
public $force_ssl = '{{ joomla_force_ssl| default(2) }}';
public $session_memcache_server_host = '{{ joomla_session_memcache_server_host| default("localhost") }}';
public $session_memcache_server_port = '{{ joomla_session_memcache_server_port| default("11211") }}';
public $session_memcached_server_host = '{{ joomla_session_memcached_server_host| default("localhost") }}';
public $session_memcached_server_port = '{{ joomla_session_memcached_server_port| default("11211") }}';
public $frontediting = '{{ joomla_frontediting| default(0) }}';
public $feed_email = '{{ joomla_feed_email| default("author") }}';
public $cookie_domain = '{{ joomla_cookie_domain| default("") }}';
public $cookie_path = '{{ joomla_cookie_path| default("") }}';
public $asset_id = '{{ joomla_asset_id| default(1) }}';
}