diff --git a/.gitignore b/.gitignore index c9b2377e..f56f5b57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.retry -tests/test.sh +*/__pycache__ +*.pyc diff --git a/.travis.yml b/.travis.yml index 2992c92c..0b366f61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,32 @@ --- +language: python services: docker env: - - distro: centos7 - - distro: centos6 - - distro: ubuntu1804 - - distro: ubuntu1604 - - distro: ubuntu1404 - - distro: debian9 - - distro: debian8 + global: + - ROLE_NAME: apache + matrix: + - MOLECULE_DISTRO: centos7 + - MOLECULE_DISTRO: centos6 + - MOLECULE_DISTRO: ubuntu1804 + - MOLECULE_DISTRO: ubuntu1604 + - MOLECULE_DISTRO: ubuntu1404 + - MOLECULE_DISTRO: debian9 + - MOLECULE_DISTRO: debian8 -script: - # Download test shim. - - wget -O ${PWD}/tests/test.sh https://gist.githubusercontent.com/geerlingguy/73ef1e5ee45d8694570f334be385e181/raw/ - - chmod +x ${PWD}/tests/test.sh +install: + # Install test dependencies. + - pip install molecule docker + +before_script: + # Use actual Ansible Galaxy role name for the project directory. + - cd ../ + - mv ansible-role-$ROLE_NAME wcm_io_devops.$ROLE_NAME + - cd wcm_io_devops.$ROLE_NAME +script: # Run tests. - - ${PWD}/tests/test.sh + - molecule test notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/defaults/main.yml b/defaults/main.yml index 639899fd..009a9689 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -31,14 +31,14 @@ apache_allow_override: "All" apache_options: "-Indexes +FollowSymLinks" apache_vhosts_ssl: [] - # Additional properties: - # 'serveradmin, serveralias, allow_override, options, extra_parameters'. - # - servername: "local.dev", - # documentroot: "/var/www/html", - # certificate_file: "/path/to/certificate.crt", - # certificate_key_file: "/path/to/certificate.key", - # # Optional. - # certificate_chain_file: "/path/to/certificate_chain.crt" +# Additional properties: +# 'serveradmin, serveralias, allow_override, options, extra_parameters'. +# - servername: "local.dev", +# documentroot: "/var/www/html", +# certificate_file: "/path/to/certificate.crt", +# certificate_key_file: "/path/to/certificate.key", +# # Optional. +# certificate_chain_file: "/path/to/certificate_chain.crt" apache_ignore_missing_ssl_certificate: true diff --git a/meta/main.yml b/meta/main.yml index ec92f181..5858df5e 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -13,6 +13,9 @@ galaxy_info: - name: EL versions: - all + - name: Fedora + versions: + - all - name: Amazon versions: - all @@ -24,9 +27,6 @@ galaxy_info: - trusty - xenial - bionic - - name: Suse - versions: - - all - name: Solaris versions: - 11.3 @@ -35,5 +35,6 @@ galaxy_info: - apache - webserver - html + - httpd -allow_duplicates: yes +allow_duplicates: true diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 00000000..2ca6feaf --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,29 @@ +--- +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:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + 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 diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml new file mode 100644 index 00000000..2c91b51a --- /dev/null +++ b/molecule/default/playbook.yml @@ -0,0 +1,21 @@ +--- +- name: Converge + hosts: all + become: true + + vars: + apache_listen_port_ssl: 443 + apache_create_vhosts: true + apache_vhosts_filename: "vhosts.conf" + apache_vhosts: + - servername: "example.com" + documentroot: "/var/www/vhosts/example_com" + + pre_tasks: + - name: Update apt cache. + apt: update_cache=yes cache_valid_time=600 + when: ansible_os_family == 'Debian' + changed_when: false + + roles: + - role: wcm_io_devops.apache diff --git a/molecule/default/yaml-lint.yml b/molecule/default/yaml-lint.yml new file mode 100644 index 00000000..a3dbc38e --- /dev/null +++ b/molecule/default/yaml-lint.yml @@ -0,0 +1,6 @@ +--- +extends: default +rules: + line-length: + max: 120 + level: warning diff --git a/tasks/configure-RedHat.yml b/tasks/configure-RedHat.yml index ee998b59..c3b9bdf3 100644 --- a/tasks/configure-RedHat.yml +++ b/tasks/configure-RedHat.yml @@ -67,4 +67,4 @@ dest: "{{ apache_conf_path }}/ssl.conf" regexp: "##\\n##\\s*SSL Virtual Host Context(.*\\n)*" when: apache_remove_default_vhost_ssl - notify: restart apache \ No newline at end of file + notify: restart apache diff --git a/tasks/main.yml b/tasks/main.yml index 0c971753..cdbcb63d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,7 +5,9 @@ - name: Include variables for Amazon Linux. include_vars: "AmazonLinux.yml" - when: ansible_distribution == "Amazon" and ansible_distribution_major_version == "NA" + when: + - ansible_distribution == "Amazon" + - ansible_distribution_major_version == "NA" - name: Define apache_packages. set_fact: @@ -17,26 +19,29 @@ # Figure out what version of Apache is installed. - name: Get installed version of Apache. - shell: "{{ apache_daemon_path }}{{ apache_daemon }} -v" + command: "{{ apache_daemon_path }}{{ apache_daemon }} -v" changed_when: false - check_mode: no + check_mode: false register: _apache_version - name: Create apache_version variable. set_fact: apache_version: "{{ _apache_version.stdout.split()[2].split('/')[1] }}" -- include_vars: apache-22.yml +- name: Include Apache 2.2 variables. + include_vars: apache-22.yml when: "apache_version.split('.')[1] == '2'" -- include_vars: apache-24.yml +- name: Include Apache 2.4 variables. + include_vars: apache-24.yml when: "apache_version.split('.')[1] == '4'" # Configure Apache. -- include_tasks: "configure-{{ ansible_os_family }}.yml" +- name: Configure Apache. + include_tasks: "configure-{{ ansible_os_family }}.yml" - name: Ensure Apache has selected state and enabled on boot. service: name: "{{ apache_service }}" state: "{{ apache_state }}" - enabled: yes + enabled: true diff --git a/tasks/setup-Debian.yml b/tasks/setup-Debian.yml index 2918b92d..b5d14123 100644 --- a/tasks/setup-Debian.yml +++ b/tasks/setup-Debian.yml @@ -3,5 +3,4 @@ apt: update_cache=yes cache_valid_time=3600 - name: Ensure Apache is installed on Debian. - apt: "name={{ item }} state={{ apache_packages_state }}" - with_items: "{{ apache_packages }}" + apt: "name={{ apache_packages }} state={{ apache_packages_state }}" diff --git a/tasks/setup-RedHat.yml b/tasks/setup-RedHat.yml index 6021b9f1..dfc90161 100644 --- a/tasks/setup-RedHat.yml +++ b/tasks/setup-RedHat.yml @@ -1,7 +1,6 @@ --- - name: Ensure Apache is installed on RHEL. - yum: - name: "{{ item }}" + package: + name: "{{ apache_packages }}" state: "{{ apache_packages_state }}" - enablerepo: "{{ apache_enablerepo }}" - with_items: "{{ apache_packages }}" + enablerepo: "{{ apache_enablerepo | default(omit, true) }}" diff --git a/tasks/setup-Solaris.yml b/tasks/setup-Solaris.yml index 91b84ff4..a4ae4504 100644 --- a/tasks/setup-Solaris.yml +++ b/tasks/setup-Solaris.yml @@ -1,6 +1,5 @@ --- - name: Ensure Apache is installed on Solaris. pkg5: - name: "{{ item }}" + name: "{{ apache_packages }}" state: "{{ apache_packages_state }}" - with_items: "{{ apache_packages }}" diff --git a/tasks/setup-Suse.yml b/tasks/setup-Suse.yml index d77ebb1f..725266b1 100644 --- a/tasks/setup-Suse.yml +++ b/tasks/setup-Suse.yml @@ -1,6 +1,5 @@ --- - name: Ensure Apache is installed on Suse. zypper: - name: "{{ item }}" + name: "{{ apache_packages }}" state: "{{ apache_packages_state }}" - with_items: "{{ apache_packages }}" diff --git a/tests/README.md b/tests/README.md deleted file mode 100644 index 6fb21172..00000000 --- a/tests/README.md +++ /dev/null @@ -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)` diff --git a/tests/test.yml b/tests/test.yml deleted file mode 100644 index f5c5ca6c..00000000 --- a/tests/test.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -- hosts: all - - vars: - apache_listen_port_ssl: 443 - apache_create_vhosts: true - apache_vhosts_filename: "vhosts.conf" - apache_vhosts: - - servername: "example.com" - documentroot: "/var/www/vhosts/example_com" - - roles: - - role_under_test diff --git a/vars/Debian.yml b/vars/Debian.yml index 91c22862..fb582b3e 100644 --- a/vars/Debian.yml +++ b/vars/Debian.yml @@ -7,4 +7,4 @@ apache_conf_path: /etc/apache2 __apache_packages: - apache2 - - apache2-utils \ No newline at end of file + - apache2-utils diff --git a/vars/Suse.yml b/vars/Suse.yml index 48c8d832..2818e755 100644 --- a/vars/Suse.yml +++ b/vars/Suse.yml @@ -9,4 +9,4 @@ apache_vhosts_version: "2.4" __apache_packages: - apache2 - - openssh \ No newline at end of file + - openssh diff --git a/vars/apache-24.yml b/vars/apache-24.yml index 83eee693..8b19aa75 100644 --- a/vars/apache-24.yml +++ b/vars/apache-24.yml @@ -9,21 +9,21 @@ apache_default_vhost_filenames: apache_ports_configuration_items: # Debian/Ubuntu and RedHat/CentOS/Amazon Linux Regex for http - { - regexp: "^Listen\\s+\\d+$", - line: "Listen {{ apache_listen_port }}" + regexp: "^Listen\\s+\\d+$", + line: "Listen {{ apache_listen_port }}" } # RedHat/CentOS 7, Amazon Linux - { - regexp: "^Listen\\s+\\d+\\s+https$", - replace: "Listen {{ apache_listen_port_ssl }} https" + regexp: "^Listen\\s+\\d+\\s+https$", + replace: "Listen {{ apache_listen_port_ssl }} https" } # Debian, SUSE - { - regexp: "^(\\s*(?:\\n+\\s+#.+)*\\s+)Listen\\s+\\d+", - replace: "\\1Listen {{ apache_listen_port_ssl }}" + regexp: "^(\\s*(?:\\n+\\s+#.+)*\\s+)Listen\\s+\\d+", + replace: "\\1Listen {{ apache_listen_port_ssl }}" } # SUSE - { - regexp: "^(# - name-based virtual hosting:\\n(?:#\\n)*)#?\\s*NameVirtualHost\\s+.*:\\d+", - replace: "\\1NameVirtualHost {{ apache_listen_ip }}:{{ apache_listen_port }}" + regexp: "^(# - name-based virtual hosting:\\n(?:#\\n)*)#?\\s*NameVirtualHost\\s+.*:\\d+", + replace: "\\1NameVirtualHost {{ apache_listen_ip }}:{{ apache_listen_port }}" }