Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Update Apache, Git, and MySQL roles.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Apr 12, 2017
1 parent 4ff0953 commit 3d432b4
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 94 deletions.
6 changes: 3 additions & 3 deletions provisioning/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- src: geerlingguy.adminer
version: 1.1.1
- src: geerlingguy.apache
version: 2.0.2
version: 2.1.0
- src: geerlingguy.apache-php-fpm
version: 1.0.2
- src: geerlingguy.blackfire
Expand All @@ -28,15 +28,15 @@
- src: geerlingguy.firewall
version: 2.2.0
- src: geerlingguy.git
version: 1.2.1
version: 1.3.0
- src: geerlingguy.java
version: 1.7.4
- src: geerlingguy.mailhog
version: 2.1.3
- src: geerlingguy.memcached
version: 1.0.7
- src: geerlingguy.mysql
version: 2.5.0
version: 2.6.0
- src: geerlingguy.nginx
version: 2.0.0
- src: geerlingguy.nodejs
Expand Down
2 changes: 1 addition & 1 deletion provisioning/roles/geerlingguy.apache/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ galaxy_info:
description: Apache 2.x for Linux.
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 1.9
min_ansible_version: 2.2
platforms:
- name: EL
versions:
Expand Down
2 changes: 1 addition & 1 deletion provisioning/roles/geerlingguy.apache/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- name: Get installed version of Apache.
shell: "{{ apache_daemon_path }}{{ apache_daemon }} -v"
changed_when: false
always_run: yes
check_mode: no
register: _apache_version

- name: Create apache_version variable.
Expand Down
3 changes: 2 additions & 1 deletion provisioning/roles/geerlingguy.git/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.LSOverride
*.retry
tests/test.sh
54 changes: 12 additions & 42 deletions provisioning/roles/geerlingguy.git/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,83 +4,53 @@ services: docker
env:
# Test source install on latest supported OSes.
- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
playbook: test-source.yml
GIT_VERSION: 2.9.3
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
playbook: test-source.yml
GIT_VERSION: 2.9.3

# Test package install on all supported OSes.
- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
playbook: test.yml
GIT_VERSION: 1.8.3.1
- distro: centos6
init: /sbin/init
run_opts: "--privileged"
playbook: test.yml
GIT_VERSION: 1.7.1
- distro: fedora24
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
playbook: test.yml
GIT_VERSION: 2.7.4
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
playbook: test.yml
GIT_VERSION: 2.7.4
- distro: ubuntu1404
init: /sbin/init
run_opts: "--privileged"
playbook: test.yml
GIT_VERSION: 1.9.1
- distro: ubuntu1204
init: /sbin/init
run_opts: "--privileged"
playbook: test.yml
GIT_VERSION: 1.7.9.5
- distro: debian8
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
playbook: test.yml
GIT_VERSION: 2.1.4

before_install:
# Pull container.
- 'docker pull geerlingguy/docker-${distro}-ansible:latest'

script:
- container_id=$(mktemp)
# Run container in detached state.
- 'docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'

# Ansible syntax check.
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} --syntax-check'
# Configure test script so we can run extra tests after playbook is run.
- export container_id=$(date +%s)
- export cleanup=false

# Test role.
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook}'
# Download test shim.
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
- chmod +x ${PWD}/tests/test.sh

# Test role idempotence.
- idempotence=$(mktemp)
- docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} | tee -a ${idempotence}
- >
tail ${idempotence}
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Run tests.
- ${PWD}/tests/test.sh

# Ensure Git is installed and at the right version.
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm which git'
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm test -x /usr/bin/git'
- 'docker exec --tty ${container_id} env TERM=xterm which git'
- 'docker exec --tty ${container_id} env TERM=xterm test -x /usr/bin/git'

- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm git --version'
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm /usr/bin/git --version | grep -qF "$GIT_VERSION"'
- 'docker exec --tty ${container_id} env TERM=xterm git --version'
- 'docker exec --tty ${container_id} env TERM=xterm /usr/bin/git --version | grep -qF "$GIT_VERSION"'

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
20 changes: 20 additions & 0 deletions provisioning/roles/geerlingguy.git/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2017 Jeff Geerling

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion provisioning/roles/geerlingguy.git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ MIT / BSD

## Author Information

This role was created in 2014 by [Jeff Geerling](http://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
This role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
2 changes: 1 addition & 1 deletion provisioning/roles/geerlingguy.git/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ galaxy_info:
description: Git version control software
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 2.0
min_ansible_version: 2.2
platforms:
- name: EL
versions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
warn=no
changed_when: false
failed_when: false
always_run: yes
check_mode: no
register: git_installed_version

- name: Force git install if the version numbers do not match
Expand Down
11 changes: 11 additions & 0 deletions provisioning/roles/geerlingguy.git/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ansible Role tests

To run the test playbook(s) in this directory:

1. Install and start Docker.
1. Download the test shim (see .travis.yml file for the URL) into `tests/test.sh`:
- `wget -O tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/`
1. Make the test shim executable: `chmod +x tests/test.sh`.
1. Run (from the role root directory) `distro=[distro] playbook=[playbook] ./tests/test.sh`

If you don't want the container to be automatically deleted after the test playbook is run, add the following environment variables: `cleanup=false container_id=$(date +%s)`
2 changes: 2 additions & 0 deletions provisioning/roles/geerlingguy.mysql/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.retry
tests/test.sh
55 changes: 16 additions & 39 deletions provisioning/roles/geerlingguy.mysql/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,50 @@ services: docker

env:
- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
playbook: centos-7-test.yml
- distro: centos6
init: /sbin/init
run_opts: ""
playbook: test.yml
- distro: ubuntu1604
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
playbook: test.yml
- distro: ubuntu1404
init: /sbin/init
run_opts: ""
playbook: test.yml

services:
- docker

before_install:
# Pull container
- 'docker pull geerlingguy/docker-${distro}-ansible:latest'

script:
- container_id=$(mktemp)
# Run container in detached state.
- 'docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"'
# Configure test script so we can run extra tests after playbook is run.
- export container_id=$(date +%s)
- export cleanup=false

# Ansible syntax check.
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} --syntax-check'
# Download test shim.
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/
- chmod +x ${PWD}/tests/test.sh

# Test role.
- 'docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook}'

# Test role idempotence.
- idempotence=$(mktemp)
- docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/role_under_test/tests/${playbook} | tee -a ${idempotence}
- >
tail ${idempotence}
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Run tests.
- ${PWD}/tests/test.sh

# Some MySQL debugging (show all the logs).
- docker exec --tty "$(cat ${container_id})" env TERM=xterm ls -lah /var/log
- docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql/error.log || true
- docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql.err || true
- docker exec --tty ${container_id} env TERM=xterm ls -lah /var/log
- docker exec --tty ${container_id} env TERM=xterm cat /var/log/mysql/error.log || true
- docker exec --tty ${container_id} env TERM=xterm cat /var/log/mysql.err || true

# Check to make sure we can connect to MySQL via Unix socket.
- >
sudo docker exec "$(cat ${container_id})" mysql -u root -proot -e 'show databases;'
sudo docker exec ${container_id} mysql -u root -proot -e 'show databases;'
| grep -q 'information_schema'
&& (echo 'MySQL running normally' && exit 0)
|| (echo 'MySQL not running' && exit 1)
# Check to make sure we can connect to MySQL via TCP.
- >
sudo docker exec "$(cat ${container_id})" mysql -u root -proot -h 127.0.0.1 -e 'show databases;'
sudo docker exec ${container_id} mysql -u root -proot -h 127.0.0.1 -e 'show databases;'
| grep -q 'information_schema'
&& (echo 'MySQL running normally' && exit 0)
|| (echo 'MySQL not running' && exit 1)
after_failure:
# Check MySQL settings.
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql/error.log'
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql.err'
- 'docker exec --tty "$(cat ${container_id})" env TERM=xterm cat /var/log/mysql.log'
- 'docker exec --tty ${container_id} env TERM=xterm cat /var/log/mysql/error.log'
- 'docker exec --tty ${container_id} env TERM=xterm cat /var/log/mysql.err'
- 'docker exec --tty ${container_id} env TERM=xterm cat /var/log/mysql.log'

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
20 changes: 20 additions & 0 deletions provisioning/roles/geerlingguy.mysql/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2017 Jeff Geerling

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 changes: 24 additions & 1 deletion provisioning/roles/geerlingguy.mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,29 @@ The rest of the settings in `defaults/main.yml` control MySQL's memory usage and

Replication settings. Set `mysql_server_id` and `mysql_replication_role` by server (e.g. the master would be ID `1`, with the `mysql_replication_role` of `master`, and the slave would be ID `2`, with the `mysql_replication_role` of `slave`). The `mysql_replication_user` uses the same keys as `mysql_users`, and is created on master servers, and used to replicate on all the slaves.

### Later versions of MySQL on CentOS 7

If you want to install MySQL from the official repository instead of installing the system default MariaDB equivalents, you can add the following `pre_tasks` task in your playbook:

```yaml
pre_tasks:
- name: Install the MySQL repo.
yum:
name: http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
state: present
when: ansible_os_family == "RedHat"

- name: Override variables for MySQL (RedHat).
set_fact:
mysql_daemon: mysqld
mysql_packages: ['mysql-server']
mysql_log_error: /var/log/mysqld.err
mysql_syslog_tag: mysqld
mysql_pid_file: /var/run/mysqld/mysqld.pid
mysql_socket: /var/lib/mysql/mysql.sock
when: ansible_os_family == "RedHat"
```
### MariaDB usage
This role works with either MySQL or a compatible version of MariaDB. On RHEL/CentOS 7+, the mariadb database engine was substituted as the default MySQL replacement package. No modifications are necessary though all of the variables still reference 'mysql' instead of mariadb.
Expand Down Expand Up @@ -152,4 +175,4 @@ MIT / BSD

## Author Information

This role was created in 2014 by [Jeff Geerling](http://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
This role was created in 2014 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/).
1 change: 1 addition & 0 deletions provisioning/roles/geerlingguy.mysql/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ mysql_port: "3306"
mysql_bind_address: '0.0.0.0'
mysql_skip_name_resolve: no
mysql_datadir: /var/lib/mysql
mysql_sql_mode: ''
# The following variables have a default value depending on operating system.
# mysql_pid_file: /var/run/mysqld/mysqld.pid
# mysql_socket: /var/lib/mysql/mysql.sock
Expand Down
2 changes: 1 addition & 1 deletion provisioning/roles/geerlingguy.mysql/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ galaxy_info:
description: MySQL server for RHEL/CentOS and Debian/Ubuntu.
company: "Midwestern Mac, LLC"
license: "license (BSD, MIT)"
min_ansible_version: 1.9
min_ansible_version: 2.2
platforms:
- name: EL
versions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
command: mysql -NBe "SELECT Host FROM mysql.user WHERE User = '{{ mysql_root_username }}' ORDER BY (Host='localhost') ASC"
register: mysql_root_hosts
changed_when: false
always_run: true
check_mode: no
when: mysql_install_packages | bool or mysql_root_password_update

# Note: We do not use mysql_user for this operation, as it doesn't always update
Expand Down Expand Up @@ -67,7 +67,7 @@
command: mysql -NBe 'SELECT Host FROM mysql.user WHERE User = ""'
register: mysql_anonymous_hosts
changed_when: false
always_run: true
check_mode: no

- name: Remove anonymous MySQL users.
mysql_user:
Expand Down
3 changes: 3 additions & 0 deletions provisioning/roles/geerlingguy.mysql/templates/my.cnf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pid-file = {{ mysql_pid_file }}
{% if mysql_skip_name_resolve %}
skip-name-resolve
{% endif %}
{% if mysql_sql_mode %}
sql_mode = {{ mysql_sql_mode }}
{% endif %}

# Logging configuration.
{% if mysql_log_error == 'syslog' or mysql_log == 'syslog' %}
Expand Down
Loading

0 comments on commit 3d432b4

Please sign in to comment.