Created
January 6, 2016 14:45
-
-
Save Dude4Linux/a4caa608fe67fbb8ef76 to your computer and use it in GitHub Desktop.
turnkey-test-app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Test a TurnKey appliance | |
hosts: lxc | |
gather_facts: false | |
vars: | |
host_key_checking: false | |
ssh_user: '{{lookup("env", "USER")}}' | |
ssh_key: '{{lookup("file", "~/.ssh/id_rsa.pub")}}' | |
app: core | |
container: "turnkey-{{app}}-container" | |
domain: "{{app}}.local.lxc" | |
tasks: | |
- debug: msg="Testing TurnKey {{app}} appliance" | |
tags: always | |
- name: Clear lxc lock | |
tags: always | |
# required by bug in ansible installaion | |
file: path=/var/lock/subsys/lxc state=absent | |
- name: Ensure known_hosts | |
tags: always | |
file: path=/root/.ssh/known_hosts state=touch mode=0644 | |
- name: Clear known_hosts | |
tags: always | |
# remove previous entries, if any, from known_hosts | |
shell: "ssh-keygen -R {{container}}" | |
shell: "ssh-keygen -R $(host {{container}} | cut -d ' ' -f 4)" | |
- name: Get list of containers | |
tags: always | |
command: "lxc-ls" | |
register: containers | |
ignore_errors: yes | |
- name: Create TurnKey container | |
tags: create | |
# Create container | |
lxc_container: | |
name: "{{container}}" | |
container_log: true | |
config: /etc/lxc/natbridge.conf | |
#backing_store: lvm | |
#vg_name: turnkey | |
state: started | |
template: turnkey | |
template_options: "{{app}}" | |
#template_options: "{{app}} --version=13.0-wheezy" | |
container_command: | | |
sleep 60 | |
# make sure required packages are present | |
apt-get -yq update | |
apt-get -yq install python python-apt | |
# install the ansible user's public key | |
mkdir -p /root/.ssh | |
echo '{{ssh_key}}' >> /root/.ssh/authorized_keys | |
when: "'{{container}}' not in containers.stdout" | |
- name: Start TurnKey container | |
tags: create | |
lxc_container: | |
name: "{{container}}" | |
state: started | |
ignore_errors: yes | |
when: "'{{container}}' in containers.stdout" | |
- name: Create web proxy | |
tags: create | |
command: "nginx-proxy -d {{domain}} -n {{container}}" | |
ignore_errors: yes | |
register: command_result | |
changed_when: "command_result.rc == 1" | |
failed_when: "command_result.rc == 2" | |
- name: Wait for webpage | |
tags: test | |
wait_for: | |
host: "{{container}}" | |
port: 80 | |
delay: 60 | |
timeout: 300 | |
register: port_80 | |
ignore_errors: yes | |
- name: Test appliance webpage | |
tags: test | |
uri: | |
url: "http://{{container}}" | |
validate_certs: no | |
# allow redirects and authorization requests | |
status_code: 200, 302, 401 | |
register: webpage | |
ignore_errors: yes | |
until: webpage|success | |
retries: 10 | |
delay: 15 | |
when: port_80|success | |
- name: Test proxy webpage | |
tags: test | |
uri: | |
url: "http://{{domain}}" | |
validate_certs: no | |
status_code: 200, 302, 401 | |
register: proxy_page | |
ignore_errors: yes | |
until: proxy_page|success | |
retries: 10 | |
delay: 10 | |
when: port_80|success | |
- name: Test appliance ssl webpage | |
tags: test | |
uri: | |
url: "https://{{container}}" | |
validate_certs: no | |
status_code: 200, 302, 401 | |
register: ssl_page | |
ignore_errors: yes | |
until: ssl_page|success | |
retries: 10 | |
delay: 10 | |
when: port_80|success | |
- name: Test proxy ssl webpage | |
tags: test | |
uri: | |
url: "https://{{domain}}" | |
validate_certs: no | |
status_code: 200, 302, 401 | |
register: proxy_ssl | |
ignore_errors: yes | |
until: proxy_ssl|success | |
retries: 10 | |
delay: 10 | |
when: port_80|success | |
- name: Test appliance shellinabox | |
tags: test | |
uri: | |
url: "https://{{container}}:12320" | |
validate_certs: no | |
register: shellinabox | |
ignore_errors: yes | |
until: shellinabox|success | |
retries: 10 | |
delay: 10 | |
- name: Test proxy shellinabox | |
tags: test | |
uri: | |
url: "https://{{domain}}:12320" | |
validate_certs: no | |
register: proxy_box | |
ignore_errors: yes | |
until: proxy_box|success | |
retries: 10 | |
delay: 10 | |
- name: Test appliance webmin | |
tags: test | |
uri: | |
url: "https://{{container}}:12321" | |
validate_certs: no | |
register: webmin | |
ignore_errors: yes | |
until: webmin|success | |
retries: 10 | |
delay: 10 | |
- name: Test proxy webmin | |
tags: test | |
uri: | |
url: "https://{{domain}}:12321" | |
validate_certs: no | |
register: proxy_min | |
ignore_errors: yes | |
until: proxy_min|success | |
retries: 10 | |
delay: 10 | |
- name: Check for adminer | |
tags: test | |
wait_for: | |
host: "{{container}}" | |
port: 12322 | |
timeout: 5 | |
register: adminer_present | |
ignore_errors: yes | |
- name: Test appliance adminer | |
tags: test | |
uri: | |
url: "https://{{container}}:12322" | |
validate_certs: no | |
register: adminer | |
ignore_errors: yes | |
until: adminer|success | |
retries: 10 | |
delay: 10 | |
when: adminer_present|success | |
- name: Test proxy adminer | |
tags: test | |
uri: | |
url: "https://{{domain}}:12322" | |
validate_certs: no | |
register: proxy_adminer | |
ignore_errors: yes | |
until: proxy_adminer|success | |
retries: 10 | |
delay: 10 | |
when: adminer_present|success | |
- name: Shutdown TurnKey container | |
tags: destroy | |
lxc_container: | |
name: "{{container}}" | |
state: stopped | |
ignore_errors: yes | |
- name: Destroy TurnKey containers | |
tags: destroy | |
# issue lxc-destroy via command to invoke wrapper script | |
command: "lxc-destroy -n {{container}}" | |
ignore_errors: yes | |
when: not ( | |
webpage|failed or | |
proxy_page|failed or | |
ssl_page|failed or | |
proxy_ssl|failed or | |
shellinabox|failed or | |
proxy_box|failed or | |
webmin|failed or | |
proxy_min|failed or | |
adminer|failed or | |
proxy_adminer|failed | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment