Merge pull request #3 from geerlingguy/master

sync upstream
pull/129/head
Ryan MacDonald 6 years ago committed by GitHub
commit 8bbc8960b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .gitignore
  2. 40
      .travis.yml
  3. 2
      README.md
  4. 7
      defaults/main.yml
  5. 2
      handlers/main.yml
  6. 26
      meta/main.yml
  7. 27
      molecule/default/molecule.yml
  8. 8
      molecule/default/playbook.yml
  9. 14
      molecule/default/tests/test_default.py
  10. 6
      molecule/default/yaml-lint.yml
  11. 2
      tasks/setup-Ubuntu.yml
  12. 6
      tasks/vhosts.yml
  13. 11
      tests/README.md

3
.gitignore vendored

@ -1,2 +1,3 @@
*.retry *.retry
tests/test.sh */__pycache__
*.pyc

@ -1,31 +1,31 @@
--- ---
language: python
services: docker services: docker
env: env:
- distro: centos7 global:
- distro: ubuntu1604 - ROLE_NAME: nginx
- distro: ubuntu1404 matrix:
- distro: debian9 - MOLECULE_DISTRO: centos7
- distro: debian8 MOLECULE_DOCKER_COMMAND: /usr/lib/systemd/systemd
- MOLECULE_DISTRO: ubuntu1604
- MOLECULE_DISTRO: ubuntu1404
- MOLECULE_DISTRO: debian9
- MOLECULE_DISTRO: debian8
script: install:
# Configure test script so we can run extra tests after playbook is run. # Install test dependencies.
- export container_id=$(date +%s) - pip install molecule docker
- export cleanup=false
# Download test shim. before_script:
- wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/ # Use actual Ansible Galaxy role name for the project directory.
- chmod +x ${PWD}/tests/test.sh - cd ../
- mv ansible-role-$ROLE_NAME geerlingguy.$ROLE_NAME
- cd geerlingguy.$ROLE_NAME
script:
# Run tests. # Run tests.
- ${PWD}/tests/test.sh - molecule test
# Setup test site.
- 'docker exec ${container_id} mkdir -p /var/www/test'
- 'docker exec ${container_id} bash -c "echo Success >| /var/www/test/index.html"'
# Make sure virtualhost exists.
- 'docker exec --tty ${container_id} env TERM=xterm curl http://localhost/ | grep "Success"'
notifications: notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/ webhooks: https://galaxy.ansible.com/api/v1/notifications/

@ -130,7 +130,7 @@ Extra lines to be inserted in the top of `nginx.conf`. The value should be defin
See the template in `templates/nginx.conf.j2` for more details on the placement. See the template in `templates/nginx.conf.j2` for more details on the placement.
nginx_log_format: | nginx_log_format: |-
'$remote_addr - $remote_user [$time_local] "$request" ' '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" ' '$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"' '"$http_user_agent" "$http_x_forwarded_for"'

@ -15,7 +15,8 @@ nginx_package_name: "nginx"
nginx_conf_template: "nginx.conf.j2" nginx_conf_template: "nginx.conf.j2"
nginx_vhost_template: "vhost.j2" nginx_vhost_template: "vhost.j2"
nginx_worker_processes: "{{ ansible_processor_vcpus | default(ansible_processor_count) }}" nginx_worker_processes: >-
"{{ ansible_processor_vcpus | default(ansible_processor_count) }}"
nginx_worker_connections: "1024" nginx_worker_connections: "1024"
nginx_multi_accept: "off" nginx_multi_accept: "off"
@ -70,7 +71,7 @@ nginx_vhosts: []
# server_name: "example.com" # default: N/A # server_name: "example.com" # default: N/A
# root: "/var/www/example.com" # default: N/A # root: "/var/www/example.com" # default: N/A
# index: "index.html index.htm" # default: "index.html index.htm" # index: "index.html index.htm" # default: "index.html index.htm"
# filename: "example.com.conf" # Can be used to set the filename of the vhost file. # filename: "example.com.conf" # Can be used to set the vhost filename.
# #
# # Properties that are only added if defined: # # Properties that are only added if defined:
# server_name_redirect: "www.example.com" # default: N/A # server_name_redirect: "www.example.com" # default: N/A
@ -91,7 +92,7 @@ nginx_upstreams: []
# "srv3.example.com" # "srv3.example.com"
# } # }
nginx_log_format: | nginx_log_format: |-
'$remote_addr - $remote_user [$time_local] "$request" ' '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" ' '$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"' '"$http_user_agent" "$http_x_forwarded_for"'

@ -4,7 +4,7 @@
- name: validate nginx configuration - name: validate nginx configuration
command: nginx -t -c /etc/nginx/nginx.conf command: nginx -t -c /etc/nginx/nginx.conf
changed_when: False changed_when: false
- name: reload nginx - name: reload nginx
service: name=nginx state=reloaded service: name=nginx state=reloaded

@ -10,29 +10,29 @@ galaxy_info:
platforms: platforms:
- name: EL - name: EL
versions: versions:
- 6 - 6
- 7 - 7
- name: Debian - name: Debian
versions: versions:
- all - all
- name: Ubuntu - name: Ubuntu
versions: versions:
- trusty - trusty
- xenial - xenial
- name: Archlinux - name: Archlinux
versions: versions:
- all - all
- name: FreeBSD - name: FreeBSD
versions: versions:
- 10.3 - 10.3
- 10.2 - 10.2
- 10.1 - 10.1
- 10.0 - 10.0
- 9.3 - 9.3
- name: OpenBSD - name: OpenBSD
versions: versions:
- 5.9 - 5.9
- 6.0 - 6.0
galaxy_tags: galaxy_tags:
- development - development
- web - web

@ -0,0 +1,27 @@
---
dependency:
name: galaxy
driver:
name: docker
lint:
name: yamllint
options:
config-file: molecule/default/yaml-lint.yml
platforms:
- name: instance
image: geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible
command: ${MOLECULE_DOCKER_COMMAND:-"sleep infinity"}
privileged: true
pre_build_image: true
provisioner:
name: ansible
lint:
name: ansible-lint
playbooks:
converge: ${MOLECULE_PLAYBOOK:-playbook.yml}
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8

@ -1,5 +1,6 @@
--- ---
- hosts: all - name: Converge
hosts: all
vars: vars:
nginx_use_ppa: true nginx_use_ppa: true
@ -14,8 +15,5 @@
when: ansible_os_family == 'Debian' when: ansible_os_family == 'Debian'
changed_when: false changed_when: false
- name: Install dependencies.
package: name=curl state=present
roles: roles:
- role_under_test - role: geerlingguy.nginx

@ -0,0 +1,14 @@
import os
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
def test_hosts_file(host):
f = host.file('/etc/hosts')
assert f.exists
assert f.user == 'root'
assert f.group == 'root'

@ -0,0 +1,6 @@
---
extends: default
rules:
line-length:
max: 120
level: warning

@ -3,7 +3,7 @@
apt_repository: apt_repository:
repo: 'ppa:nginx/{{ nginx_ppa_version }}' repo: 'ppa:nginx/{{ nginx_ppa_version }}'
state: present state: present
update_cache: yes update_cache: true
register: nginx_ppa_added register: nginx_ppa_added
when: nginx_ppa_use when: nginx_ppa_use

@ -16,13 +16,15 @@
template: template:
src: "{{ item.template|default(nginx_vhost_template) }}" src: "{{ item.template|default(nginx_vhost_template) }}"
dest: "{{ nginx_vhost_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}" dest: "{{ nginx_vhost_path }}/{{ item.filename|default(item.server_name.split(' ')[0] ~ '.conf') }}"
force: yes force: true
owner: root owner: root
group: root group: root
mode: 0644 mode: 0644
when: item.state|default('present') != 'absent' when: item.state|default('present') != 'absent'
with_items: "{{ nginx_vhosts }}" with_items: "{{ nginx_vhosts }}"
notify: reload nginx notify: reload nginx
tags:
- skip_ansible_lint
- name: Remove managed vhost config files. - name: Remove managed vhost config files.
file: file:
@ -31,6 +33,8 @@
when: item.state|default('present') == 'absent' when: item.state|default('present') == 'absent'
with_items: "{{ nginx_vhosts }}" with_items: "{{ nginx_vhosts }}"
notify: reload nginx notify: reload nginx
tags:
- skip_ansible_lint
- name: Remove legacy vhosts.conf file. - name: Remove legacy vhosts.conf file.
file: file:

@ -1,11 +0,0 @@
# 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)`