From 58ac7a8a7a14d0ab76b9c8bc95ef4e117d580edb Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Fri, 9 Oct 2015 11:03:29 +0100 Subject: [PATCH] Enable role testing and make structure ansible-galaxy compatible This patch adds the bits needed to implement automated syntax/lint role testing. It also moves the role into the base repository so that the role becomes fully compatible with ansible-galaxy to improve the role's consumability. Change-Id: Ia79cd5dedbbe50dfdf46688830a989ff0897832a --- .../README.md => README.md | 0 .../defaults => defaults}/main.yml | 0 .../files => files}/login_banner.txt | 0 .../handlers => handlers}/main.yml | 0 .../meta => meta}/main.yml | 0 run_tests.sh | 22 +++++++++++++++++++ .../tasks => tasks}/apt.yml | 0 .../tasks => tasks}/auditd.yml | 0 .../tasks => tasks}/auth.yml | 0 .../tasks => tasks}/boot.yml | 0 .../tasks => tasks}/console.yml | 0 .../tasks => tasks}/file_perms.yml | 0 .../tasks => tasks}/kernel.yml | 0 .../tasks => tasks}/mail.yml | 0 .../tasks => tasks}/main.yml | 0 .../tasks => tasks}/misc.yml | 0 .../tasks => tasks}/nfsd.yml | 0 .../tasks => tasks}/services.yml | 0 .../tasks => tasks}/sshd.yml | 0 .../templates => templates}/chrony.conf.j2 | 0 .../templates => templates}/osas-auditd.j2 | 0 tests/ansible.cfg | 2 ++ tests/inventory | 2 ++ tests/test.yml | 19 ++++++++++++++++ .../vars => vars}/main.yml | 0 25 files changed, 45 insertions(+) rename openstack-ansible-security/README.md => README.md (100%) rename {openstack-ansible-security/defaults => defaults}/main.yml (100%) rename {openstack-ansible-security/files => files}/login_banner.txt (100%) rename {openstack-ansible-security/handlers => handlers}/main.yml (100%) rename {openstack-ansible-security/meta => meta}/main.yml (100%) create mode 100755 run_tests.sh rename {openstack-ansible-security/tasks => tasks}/apt.yml (100%) rename {openstack-ansible-security/tasks => tasks}/auditd.yml (100%) rename {openstack-ansible-security/tasks => tasks}/auth.yml (100%) rename {openstack-ansible-security/tasks => tasks}/boot.yml (100%) rename {openstack-ansible-security/tasks => tasks}/console.yml (100%) rename {openstack-ansible-security/tasks => tasks}/file_perms.yml (100%) rename {openstack-ansible-security/tasks => tasks}/kernel.yml (100%) rename {openstack-ansible-security/tasks => tasks}/mail.yml (100%) rename {openstack-ansible-security/tasks => tasks}/main.yml (100%) rename {openstack-ansible-security/tasks => tasks}/misc.yml (100%) rename {openstack-ansible-security/tasks => tasks}/nfsd.yml (100%) rename {openstack-ansible-security/tasks => tasks}/services.yml (100%) rename {openstack-ansible-security/tasks => tasks}/sshd.yml (100%) rename {openstack-ansible-security/templates => templates}/chrony.conf.j2 (100%) rename {openstack-ansible-security/templates => templates}/osas-auditd.j2 (100%) create mode 100644 tests/ansible.cfg create mode 100644 tests/inventory create mode 100644 tests/test.yml rename {openstack-ansible-security/vars => vars}/main.yml (100%) diff --git a/openstack-ansible-security/README.md b/README.md similarity index 100% rename from openstack-ansible-security/README.md rename to README.md diff --git a/openstack-ansible-security/defaults/main.yml b/defaults/main.yml similarity index 100% rename from openstack-ansible-security/defaults/main.yml rename to defaults/main.yml diff --git a/openstack-ansible-security/files/login_banner.txt b/files/login_banner.txt similarity index 100% rename from openstack-ansible-security/files/login_banner.txt rename to files/login_banner.txt diff --git a/openstack-ansible-security/handlers/main.yml b/handlers/main.yml similarity index 100% rename from openstack-ansible-security/handlers/main.yml rename to handlers/main.yml diff --git a/openstack-ansible-security/meta/main.yml b/meta/main.yml similarity index 100% rename from openstack-ansible-security/meta/main.yml rename to meta/main.yml diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 00000000..2d736749 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash -e -v -x +# Copyright 2015, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ROLE_NAME=$(basename $(pwd)) + +pushd tests + ansible-playbook -i inventory --syntax-check --list-tasks test.yml -e rolename=${ROLE_NAME} +popd + +ansible-lint */*yml diff --git a/openstack-ansible-security/tasks/apt.yml b/tasks/apt.yml similarity index 100% rename from openstack-ansible-security/tasks/apt.yml rename to tasks/apt.yml diff --git a/openstack-ansible-security/tasks/auditd.yml b/tasks/auditd.yml similarity index 100% rename from openstack-ansible-security/tasks/auditd.yml rename to tasks/auditd.yml diff --git a/openstack-ansible-security/tasks/auth.yml b/tasks/auth.yml similarity index 100% rename from openstack-ansible-security/tasks/auth.yml rename to tasks/auth.yml diff --git a/openstack-ansible-security/tasks/boot.yml b/tasks/boot.yml similarity index 100% rename from openstack-ansible-security/tasks/boot.yml rename to tasks/boot.yml diff --git a/openstack-ansible-security/tasks/console.yml b/tasks/console.yml similarity index 100% rename from openstack-ansible-security/tasks/console.yml rename to tasks/console.yml diff --git a/openstack-ansible-security/tasks/file_perms.yml b/tasks/file_perms.yml similarity index 100% rename from openstack-ansible-security/tasks/file_perms.yml rename to tasks/file_perms.yml diff --git a/openstack-ansible-security/tasks/kernel.yml b/tasks/kernel.yml similarity index 100% rename from openstack-ansible-security/tasks/kernel.yml rename to tasks/kernel.yml diff --git a/openstack-ansible-security/tasks/mail.yml b/tasks/mail.yml similarity index 100% rename from openstack-ansible-security/tasks/mail.yml rename to tasks/mail.yml diff --git a/openstack-ansible-security/tasks/main.yml b/tasks/main.yml similarity index 100% rename from openstack-ansible-security/tasks/main.yml rename to tasks/main.yml diff --git a/openstack-ansible-security/tasks/misc.yml b/tasks/misc.yml similarity index 100% rename from openstack-ansible-security/tasks/misc.yml rename to tasks/misc.yml diff --git a/openstack-ansible-security/tasks/nfsd.yml b/tasks/nfsd.yml similarity index 100% rename from openstack-ansible-security/tasks/nfsd.yml rename to tasks/nfsd.yml diff --git a/openstack-ansible-security/tasks/services.yml b/tasks/services.yml similarity index 100% rename from openstack-ansible-security/tasks/services.yml rename to tasks/services.yml diff --git a/openstack-ansible-security/tasks/sshd.yml b/tasks/sshd.yml similarity index 100% rename from openstack-ansible-security/tasks/sshd.yml rename to tasks/sshd.yml diff --git a/openstack-ansible-security/templates/chrony.conf.j2 b/templates/chrony.conf.j2 similarity index 100% rename from openstack-ansible-security/templates/chrony.conf.j2 rename to templates/chrony.conf.j2 diff --git a/openstack-ansible-security/templates/osas-auditd.j2 b/templates/osas-auditd.j2 similarity index 100% rename from openstack-ansible-security/templates/osas-auditd.j2 rename to templates/osas-auditd.j2 diff --git a/tests/ansible.cfg b/tests/ansible.cfg new file mode 100644 index 00000000..6c8a3443 --- /dev/null +++ b/tests/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +roles_path = ../.. diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 00000000..df8b5f69 --- /dev/null +++ b/tests/inventory @@ -0,0 +1,2 @@ +[all] +localhost ansible_connection=local diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 00000000..942f6409 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,19 @@ +--- +# Copyright 2015, Rackspace US, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Playbook for role testing + hosts: localhost + roles: + - role: "{{ rolename }}" diff --git a/openstack-ansible-security/vars/main.yml b/vars/main.yml similarity index 100% rename from openstack-ansible-security/vars/main.yml rename to vars/main.yml