From 624d63c68f99dce42dcd76c9a1ec3927e13216b9 Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Mon, 2 Jan 2017 16:55:10 -0600 Subject: [PATCH 1/9] Use systemd unit files for systemd systems. --- .travis.yml | 3 +++ tasks/main.yml | 14 ++++++++++++++ templates/selenium-unit.j2 | 11 +++++++++++ 3 files changed, 28 insertions(+) create mode 100644 templates/selenium-unit.j2 diff --git a/.travis.yml b/.travis.yml index cb75c49..fbe4060 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,9 @@ env: - distro: ubuntu1604 init: /lib/systemd/systemd run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" + - distro: debian8 + init: /lib/systemd/systemd + run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro" - distro: ubuntu1404 init: /sbin/init run_opts: "--privileged" diff --git a/tasks/main.yml b/tasks/main.yml index 2833325..164e31c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -67,6 +67,20 @@ mode: 0755 tags: [configuration, selenium, selenium-install] +- name: Install systemd unit file (for systemd systems) + template: + src: "selenium-unit.j2" + dest: /etc/systemd/system/selenium.service + owner: root + group: root + mode: 0755 + when: > + (ansible_distribution == 'Ubuntu' and ansible_distribution_version == '16.04') or + (ansible_distribution == 'Debian' and ansible_distribution_version|int >= 8) or + (ansible_distribution == 'CentOS' and ansible_distribution_version|int >= 7) or + (ansible_distribution == 'Fedora') + tags: [configuration, selenium, selenium-install] + - name: Ensure selenium is running service: name=selenium state=started enabled=yes tags: [configuration, selenium, selenium-run] diff --git a/templates/selenium-unit.j2 b/templates/selenium-unit.j2 new file mode 100644 index 0000000..ff10536 --- /dev/null +++ b/templates/selenium-unit.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=selenium test framework +After=syslog.target network.target + +[Service] +ExecStart=/usr/bin/xvfb-run /usr/bin/java -client -jar {{ selenium_install_dir }}/selenium/selenium-server-standalone-{{ selenium_version }}.jar +Restart=on-failure +RestartSec=20s + +[Install] +WantedBy=multi-user.target From e666ca1260e5e98d9dc9fb4f5d7a016f305f9bb4 Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Mon, 2 Jan 2017 17:02:54 -0600 Subject: [PATCH 2/9] Systemd wasn't being used in centos 7. --- tasks/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 164e31c..406ee6f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -75,9 +75,9 @@ group: root mode: 0755 when: > - (ansible_distribution == 'Ubuntu' and ansible_distribution_version == '16.04') or - (ansible_distribution == 'Debian' and ansible_distribution_version|int >= 8) or - (ansible_distribution == 'CentOS' and ansible_distribution_version|int >= 7) or + (ansible_distribution == 'Ubuntu' and ansible_distribution_version.split(".")[0]|int >= 16) or + (ansible_distribution == 'Debian' and ansible_distribution_version.split(".")[0]|int >= 8) or + (ansible_distribution == 'CentOS' and ansible_distribution_version.split(".")[0]|int >= 7) or (ansible_distribution == 'Fedora') tags: [configuration, selenium, selenium-install] From 34cdc267bf8138752876280df0e46291390421f5 Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Mon, 2 Jan 2017 17:14:04 -0600 Subject: [PATCH 3/9] Add idempotence to update_cache task. --- tests/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.yml b/tests/test.yml index fa569fc..2cddb93 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -4,7 +4,7 @@ pre_tasks: - name: Update apt cache. - apt: update_cache=yes + apt: update_cache=yes cache_valid_time=3600 when: ansible_os_family == 'Debian' roles: From 6b270308e955417d4640fd96b19292f186678bdf Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Mon, 2 Jan 2017 17:48:48 -0600 Subject: [PATCH 4/9] Added idempotence for systemd systems. --- tasks/main.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tasks/main.yml b/tasks/main.yml index 406ee6f..881596f 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -81,6 +81,21 @@ (ansible_distribution == 'Fedora') tags: [configuration, selenium, selenium-install] +- name: Register systemd service status (for systemd systems) + shell: 'systemctl status selenium | grep "active (running)"' + when: > + (ansible_distribution == 'Ubuntu' and ansible_distribution_version.split(".")[0]|int >= 16) or + (ansible_distribution == 'Debian' and ansible_distribution_version.split(".")[0]|int >= 8) or + (ansible_distribution == 'CentOS' and ansible_distribution_version.split(".")[0]|int >= 7) or + (ansible_distribution == 'Fedora') + register: selenium_running + ignore_errors: yes + changed_when: false + +- name: Debug + debug: var=selenium_running + - name: Ensure selenium is running service: name=selenium state=started enabled=yes tags: [configuration, selenium, selenium-run] + when: selenium_running.failed is defined and selenium_running.failed == true From c1a74a5a4508f4db7b88f18225a7c72616d27a3e Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Mon, 2 Jan 2017 17:58:33 -0600 Subject: [PATCH 5/9] Add java dependency. --- .travis.yml | 3 +++ tests/requirements.yml | 2 ++ tests/test.yml | 1 + 3 files changed, 6 insertions(+) create mode 100644 tests/requirements.yml diff --git a/.travis.yml b/.travis.yml index fbe4060..91d5f48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,9 @@ script: # Run container in detached state. - 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"' + # Install dependencies. + - 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install -r /etc/ansible/roles/role_under_test/tests/requirements.yml' + # Ansible syntax check. - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check' diff --git a/tests/requirements.yml b/tests/requirements.yml new file mode 100644 index 0000000..8fbe7cb --- /dev/null +++ b/tests/requirements.yml @@ -0,0 +1,2 @@ +--- +- src: geerlingguy.java diff --git a/tests/test.yml b/tests/test.yml index 2cddb93..0ace42e 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -8,4 +8,5 @@ when: ansible_os_family == 'Debian' roles: + - geerlingguy.java - role_under_test From 347e4f66c80a1643f9dea54188788267fdc226d2 Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Mon, 2 Jan 2017 17:58:45 -0600 Subject: [PATCH 6/9] Remove debug info. --- tasks/main.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/tasks/main.yml b/tasks/main.yml index 881596f..f784125 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -92,9 +92,6 @@ ignore_errors: yes changed_when: false -- name: Debug - debug: var=selenium_running - - name: Ensure selenium is running service: name=selenium state=started enabled=yes tags: [configuration, selenium, selenium-run] From b900519d7696cbbd02cbe5b9545cccac978068d2 Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Mon, 2 Jan 2017 17:59:49 -0600 Subject: [PATCH 7/9] Travis syntax error. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 91d5f48..cc07197 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ script: - 'sudo docker run --detach --volume="${PWD}":/etc/ansible/roles/role_under_test:ro ${run_opts} geerlingguy/docker-${distro}-ansible:latest "${init}" > "${container_id}"' # Install dependencies. - - 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install -r /etc/ansible/roles/role_under_test/tests/requirements.yml' + - 'sudo docker exec "$(cat ${container_id})" ansible-galaxy install -r /etc/ansible/roles/role_under_test/tests/requirements.yml' # Ansible syntax check. - 'sudo docker exec --tty "$(cat ${container_id})" env TERM=xterm ansible-playbook /etc/ansible/roles/role_under_test/tests/test.yml --syntax-check' From 5bea352ab0b0c9a83cecf97aa99daca7e851435c Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Mon, 2 Jan 2017 18:24:46 -0600 Subject: [PATCH 8/9] Try to install chrome from repo for debian family. --- tasks/main.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index f784125..f9dc23e 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -23,9 +23,24 @@ when: selenium_install_firefox tags: [configuration, selenium, selenium-firefox] +- name: Add Chrome key (if configured, Debian) + apt_key: + url: "https://dl-ssl.google.com/linux/linux_signing_key.pub" + state: present + when: ansible_os_family == 'Debian' and selenium_install_chrome + tags: [configuration, selenium, selenium-chrome] + +- name: Add Chrome repo (if configured, Debian) + apt_repository: + repo: "deb http://dl.google.com/linux/chrome/deb/ stable main" + state: present + update_cache: yes + when: ansible_os_family == 'Debian' and selenium_install_chrome + tags: [configuration, selenium, selenium-chrome] + - name: Install Chrome (if configured, Debian) apt: - deb: https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb + name: google-chrome-stable state: present when: ansible_os_family == 'Debian' and selenium_install_chrome tags: [configuration, selenium, selenium-chrome] From bde2be7009777daae529fff15e1fac7f93bdd237 Mon Sep 17 00:00:00 2001 From: Jeff Geerling Date: Tue, 3 Jan 2017 11:29:18 -0600 Subject: [PATCH 9/9] Fix broken tests - don't install Chrome on older OSes. --- tests/test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/test.yml b/tests/test.yml index 0ace42e..4fb579e 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -7,6 +7,14 @@ apt: update_cache=yes cache_valid_time=3600 when: ansible_os_family == 'Debian' + - name: Don't install Chrome on old OSes. + set_fact: + selenium_install_firefox: yes + selenium_install_chrome: no + when: > + (ansible_distribution == 'Ubuntu' and ansible_distribution_version == '12.04') + or (ansible_os_family == 'RedHat' and ansible_distribution_version.split('.')[0] == '6') + roles: - geerlingguy.java - role_under_test