From d523d3b28a86d7bbcc285c6ee577cf57cecae5a8 Mon Sep 17 00:00:00 2001 From: cintom00 Date: Mon, 19 Feb 2018 10:47:16 +0100 Subject: [PATCH 1/6] Adding test folder for travis --- .travis.yml | 30 ++++++++++++++-- tests/installPython.sh | 81 ++++++++++++++++++++++++++++++++++++++++++ tests/inventory | 1 + tests/test.yml | 5 +++ 4 files changed, 114 insertions(+), 3 deletions(-) create mode 100755 tests/installPython.sh create mode 100644 tests/inventory create mode 100644 tests/test.yml diff --git a/.travis.yml b/.travis.yml index 9086f9a..86c4749 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,34 @@ -language: python +os: osx +sudo: required env: - - ANSIBLE_VERSION: "2.3.2.0" + - ANSIBLE_VERSION: "2.4.3.0" + +before_install: + - ./tests/installPython.sh + +install: + # Install Ansible. + - sudo pip install ansible + + # Add ansible.cfg to pick up roles path. + - "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg" + + # Check if ansible cfg was created correctly + - cat ansible.cfg script: - - echo "Tests to be defined" + - ansible-playbook -i tests/inventory tests/test.yml --syntax-check + + # Run the role/playbook with ansible-playbook. + - sudo ansible-playbook -i tests/inventory tests/test.yml --connection=local + + # Run the role/playbook again, checking to make sure it's idempotent. + - > + sudo ansible-playbook -i tests/inventory tests/test.yml --connection=local + | grep -q 'changed=0.*failed=0' + && (echo 'Idempotence test: pass' && exit 0) + || (echo 'Idempotence test: fail' && exit 1) notifications: # Always send email notification diff --git a/tests/installPython.sh b/tests/installPython.sh new file mode 100755 index 0000000..4099ae4 --- /dev/null +++ b/tests/installPython.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +set -e +set -x + +if [[ "$(uname -s)" == 'Darwin' ]]; then + sw_vers + brew update || brew update + + brew outdated openssl || brew upgrade openssl + brew install openssl@1.1 + + # install pyenv + git clone --depth 1 https://github.com/pyenv/pyenv ~/.pyenv + PYENV_ROOT="$HOME/.pyenv" + PATH="$PYENV_ROOT/bin:$PATH" + eval "$(pyenv init -)" + + case "${TOXENV}" in + py27) + curl -O https://bootstrap.pypa.io/get-pip.py + python get-pip.py --user + ;; + py33) + pyenv install 3.3.6 + pyenv global 3.3.6 + ;; + py34) + pyenv install 3.4.6 + pyenv global 3.4.6 + ;; + py35) + pyenv install 3.5.3 + pyenv global 3.5.3 + ;; + py36) + pyenv install 3.6.1 + pyenv global 3.6.1 + ;; + pypy*) + pyenv install "$PYPY_VERSION" + pyenv global "$PYPY_VERSION" + ;; + pypy3) + pyenv install pypy3-2.4.0 + pyenv global pypy3-2.4.0 + ;; + docs) + brew install enchant + curl -O https://bootstrap.pypa.io/get-pip.py + python get-pip.py --user + ;; + esac + pyenv rehash + sudo easy_install pip + python -m pip install --user virtualenv +else + # download, compile, and install if it's not already present via travis + # cache + if [ -n "${OPENSSL}" ]; then + OPENSSL_DIR="ossl-1/${OPENSSL}" + if [[ ! -f "$HOME/$OPENSSL_DIR/bin/openssl" ]]; then + curl -O https://www.openssl.org/source/openssl-$OPENSSL.tar.gz + tar zxf openssl-$OPENSSL.tar.gz + cd openssl-$OPENSSL + ./config shared no-asm no-ssl2 no-ssl3 -fPIC --prefix="$HOME/$OPENSSL_DIR" + # modify the shlib version to a unique one to make sure the dynamic + # linker doesn't load the system one. This isn't required for 1.1.0 at the + # moment since our Travis builders have a diff shlib version, but it doesn't hurt + sed -i "s/^SHLIB_MAJOR=.*/SHLIB_MAJOR=100/" Makefile + sed -i "s/^SHLIB_MINOR=.*/SHLIB_MINOR=0.0/" Makefile + sed -i "s/^SHLIB_VERSION_NUMBER=.*/SHLIB_VERSION_NUMBER=100.0.0/" Makefile + make depend + make install + fi + fi + pip install virtualenv +fi + +python -m virtualenv ~/.venv +source ~/.venv/bin/activate diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..2fbb50c --- /dev/null +++ b/tests/inventory @@ -0,0 +1 @@ +localhost diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..fc218a9 --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - macos_profile From 16ba6d658518ed9cd1dead56b37531c0137cc662 Mon Sep 17 00:00:00 2001 From: cintom00 Date: Mon, 19 Feb 2018 11:00:57 +0100 Subject: [PATCH 2/6] Trying to fix ansible error --- tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index ee2b402..ca7e900 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,6 +1,6 @@ --- -- name: "Set profile file name to {{ macos_profile__identifierPrefix }}.{{ mobileconfig.template }}" +- name: Set profile file name to "{{ macos_profile__identifierPrefix }}"."{{ mobileconfig.template }}" set_fact: macos_profile__profile: "{{ macos_profile__identifierPrefix }}.{{ mobileconfig.template }}" From b73dec9a91656405ad2b328df01f2ff207c185ef Mon Sep 17 00:00:00 2001 From: cintom00 Date: Mon, 19 Feb 2018 11:21:13 +0100 Subject: [PATCH 3/6] Adding missing args when starting the role --- tasks/main.yml | 2 +- tests/test.yml | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index ca7e900..ee2b402 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,6 +1,6 @@ --- -- name: Set profile file name to "{{ macos_profile__identifierPrefix }}"."{{ mobileconfig.template }}" +- name: "Set profile file name to {{ macos_profile__identifierPrefix }}.{{ mobileconfig.template }}" set_fact: macos_profile__profile: "{{ macos_profile__identifierPrefix }}.{{ mobileconfig.template }}" diff --git a/tests/test.yml b/tests/test.yml index fc218a9..14cd451 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,5 +1,7 @@ --- - hosts: localhost remote_user: root + vars: + - mobileconfig: { template: "finder", state: "present" } roles: - - macos_profile + - role: macos_profile From 3c0d9b1250e5999fe250fe0cfcfd30761d05fad7 Mon Sep 17 00:00:00 2001 From: cintom00 Date: Mon, 19 Feb 2018 12:03:43 +0100 Subject: [PATCH 4/6] Running tests with all profiles --- tests/test.yml | 247 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) diff --git a/tests/test.yml b/tests/test.yml index 14cd451..37127a9 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -1,7 +1,254 @@ --- +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "airport", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "applicationaccess", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "applicationaccessnew", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "directory", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "disableautoupdates", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "dock", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "energysaver", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "familycontrols", state: "present" } + roles: + - role: macos_profile + - hosts: localhost remote_user: root vars: - mobileconfig: { template: "finder", state: "present" } roles: - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "gatekeeper", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "loginitems", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "loginwindow", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "menuextras", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "munki", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "safari", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "sal", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "skipsetup", state: "present" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "softwareupdate", state: "present" } + roles: + - role: macos_profile + +# Remove profiles again + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "airport", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "applicationaccess", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "applicationaccessnew", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "directory", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "disableautoupdates", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "dock", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "energysaver", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "familycontrols", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "finder", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "gatekeeper", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "loginitems", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "loginwindow", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "menuextras", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "munki", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "safari", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "sal", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "skipsetup", state: "absent" } + roles: + - role: macos_profile + +- hosts: localhost + remote_user: root + vars: + - mobileconfig: { template: "softwareupdate", state: "absent" } + roles: + - role: macos_profile From fe8668c4851a65ef43edbfb1cde322639a117739 Mon Sep 17 00:00:00 2001 From: cintom00 Date: Mon, 19 Feb 2018 12:24:25 +0100 Subject: [PATCH 5/6] Removing directory template from test because ad is required --- tests/test.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/test.yml b/tests/test.yml index 37127a9..27306e8 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -20,12 +20,12 @@ roles: - role: macos_profile -- hosts: localhost - remote_user: root - vars: - - mobileconfig: { template: "directory", state: "present" } - roles: - - role: macos_profile +#- hosts: localhost +# remote_user: root +# vars: +# - mobileconfig: { template: "directory", state: "present" } +# roles: +# - role: macos_profile - hosts: localhost remote_user: root @@ -148,12 +148,12 @@ roles: - role: macos_profile -- hosts: localhost - remote_user: root - vars: - - mobileconfig: { template: "directory", state: "absent" } - roles: - - role: macos_profile +#- hosts: localhost +# remote_user: root +# vars: +# - mobileconfig: { template: "directory", state: "absent" } +# roles: +# - role: macos_profile - hosts: localhost remote_user: root From bab1c36e6d0835d56d727e5e079600ba9be4f997 Mon Sep 17 00:00:00 2001 From: cintom00 Date: Mon, 19 Feb 2018 12:33:30 +0100 Subject: [PATCH 6/6] Removing idempotent test part --- .travis.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 86c4749..8e73d4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,20 +15,20 @@ install: - "{ echo '[defaults]'; echo 'roles_path = ../'; } >> ansible.cfg" # Check if ansible cfg was created correctly - - cat ansible.cfg + - cat ansible.cfg script: - ansible-playbook -i tests/inventory tests/test.yml --syntax-check - + # Run the role/playbook with ansible-playbook. - sudo ansible-playbook -i tests/inventory tests/test.yml --connection=local - + # Run the role/playbook again, checking to make sure it's idempotent. - - > - sudo ansible-playbook -i tests/inventory tests/test.yml --connection=local - | grep -q 'changed=0.*failed=0' - && (echo 'Idempotence test: pass' && exit 0) - || (echo 'Idempotence test: fail' && exit 1) + #- > + # sudo ansible-playbook -i tests/inventory tests/test.yml --connection=local + # | grep -q 'changed=0.*failed=0' + # && (echo 'Idempotence test: pass' && exit 0) + # || (echo 'Idempotence test: fail' && exit 1) notifications: # Always send email notification