Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install under specific user + RedHat + Solenoid-UI #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
selenoid_version: 1.6.0 # Install selenoid version
selenoid_cm_version: 1.4.2 # Install configuration manager version
selenoid_version: 1.9.3 # Install selenoid version
selenoid_cm_version: latest # Install configuration manager version
selenoid_limit: 5 # Total number of simultaneously running containers http://aerokube.com/selenoid/latest/#_recommended_docker_settings
selenoid_tmpfs: 128 # Add in-memory filesystem (tmpfs) to container http://aerokube.com/selenoid/latest/#_other_optional_fields
selenoid_config_dir: /root/.aerokube/selenoid # Selenoid configuration dir
selenoid_config_dir: "{{ ansible_env.HOME }}/selenoid" # Selenoid configuration dir
selenoid_listen_port: 4444 # Listen port
selenoid_ui_listen_port: 8080 # Listen port
selenoid_time_zone: Europe/Moscow # Timezone in container
selenoid_browsers_last_versions: 5 # How many last version browsers need download in selenoid
selenoid_browsers: # What browsers to download
Expand All @@ -13,3 +14,4 @@ selenoid_browsers: # What browsers to download
- chrome
selenoid_video_host_output_dir: /var/lib/selenoid/video # Dir for save video in host path
selenoid_video_container_output_dir: /opt/selenoid/video # Dir for save video in container (default: /opt/selenoid/video)
selenoid_owner_user: "{{ ansible_env.USER }}"
107 changes: 94 additions & 13 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,126 @@
---
- name: Selenoid | Install certain python modules for docker
pip:
- name: "Selenoid | Install certain python modules for docker (RedHat)"
become: True
package:
name: "{{ item.name }}"
with_items:
- { name: docker }
- { name: python-docker-py }
when:
- ansible_os_family == "RedHat"

- name: "Selenoid | Install certain python modules for docker (Debian)"
become: True
package:
name: "{{ item.name }}"
with_items:
- { name: python-docker }
when:
- ansible_os_family == "Debian"


- name: Selenoid | Check selenoid container exist
shell: 'docker ps -aq --filter "name={{ item }}"'
become: True
become_user: "{{selenoid_owner_user}}"
# Normally must be name=^{{ item }}$ but we have seen problem on some hosts with cap (^)
shell: "docker ps -aq --filter \"name={{ item }}$\""
with_items:
- 'selenoid'
- 'selenoid-ui'
register: found_containers
tags:
- stop_selenoid

- name: Selenoid | Remove selenoid container if exist
become: True
become_user: "{{selenoid_owner_user}}"
shell: 'docker stop {{ item.item }} && docker rm -fv {{ item.item }}'
with_items: '{{ found_containers.results }}'
when: item.stdout
tags:
- stop_selenoid

- name: Selenoid | Create video folder
# I see that "cm" does not mount selenoid_video_host_output_dir in according to OVERRIDE_VIDEO_OUTPUT_DIR (ignore it)
# so video will be in {{ selenoid_config_dir }}/.aerokube/selenoid/video:
- name: Selenoid | Link video folder (due BUG in cm for OVERRIDE_VIDEO_OUTPUT_DIR )
become: True
become_user: "{{selenoid_owner_user}}"
file:
path: "{{ selenoid_video_host_output_dir }}"
state: directory
state: link
src: "{{ selenoid_config_dir }}/.aerokube/selenoid/video"
force: yes
mode: 0755


- name: Selenoid | Run CM container, download browser images and run selenoid
become: True
become_user: "{{selenoid_owner_user}}"
docker_container:
name: cm
image: "aerokube/cm:{{ selenoid_cm_version }}"
# auto_remove: yes
# Need to remove CM container before next invocation.....
# But this command run for long time to download containers
cleanup: yes
detach: no
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/root:/root"
- "{{ selenoid_video_host_output_dir }}:{{ selenoid_video_container_output_dir }}"
# due cm save config to /root inside container
- "{{ selenoid_config_dir }}:/root"
env:
TZ: "{{ selenoid_time_zone }}"
OVERRIDE_HOME: "/root"
OVERRIDE_HOME: "{{ selenoid_config_dir }}"
OVERRIDE_VIDEO_OUTPUT_DIR: "{{ selenoid_video_host_output_dir }}"
# in child container we will have mounts: "{{ selenoid_config_dir }}.aerokube/selenoid:/etc/selenoid:ro,Z"
command: >
selenoid start
--config-dir {{ selenoid_config_dir }}
--version {{ selenoid_version }}
--tmpfs {{ selenoid_tmpfs }}
--browsers {% for browser in selenoid_browsers -%}{{ browser }}{%- if not loop.last -%},{%- endif -%}{%- endfor %}
--browsers {% for browser in selenoid_browsers -%}'{{ browser }}'{%- if not loop.last -%};{%- endif -%}{%- endfor %}
--last-versions {{ selenoid_browsers_last_versions }}
--force
--vnc
--args "-limit {{ selenoid_limit }} -listen :{{ selenoid_listen_port }} -video-output-dir={{ selenoid_video_container_output_dir }} -conf /etc/selenoid/browsers.json"
--env OVERRIDE_VIDEO_OUTPUT_DIR={{ selenoid_video_host_output_dir }}
--args "-limit {{ selenoid_limit }} -listen :{{ selenoid_listen_port }}"
register: reg_cm_solenoid

- name: Print some debug information
vars:
msg: |
reg_cm_solenoid: {{ reg_cm_solenoid }}
debug:
msg: "{{ msg.split('\n') }}"
tags: debug_info


- name: Selenoid | Run CM selenoid-ui
become: True
become_user: "{{selenoid_owner_user}}"
docker_container:
name: cm
# auto_remove: yes
cleanup: yes
detach: no
image: "aerokube/cm:{{ selenoid_cm_version }}"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "{{ selenoid_config_dir }}:/root"
env:
TZ: "{{ selenoid_time_zone }}"
OVERRIDE_HOME: "{{ selenoid_config_dir }}"
# DOCKER_API_VERSION: "{{ selenoid_docker_api_version | string }}"
# --args "--selenoid-uri http://selenoid:{{ selenoid_listen_port }} --webdriver-uri http://{{selenoid_host_external}}:{{ selenoid_listen_port }}"
command: >
selenoid-ui start
--port {{ selenoid_ui_listen_port }}
register: reg_cm_solenoidui

- name: Print some debug information
vars:
msg: |
Ansible Distribution: {{ ansible_distribution }}
Ansible Dist version: {{ ansible_distribution_version }}
Ansible OS family {{ansible_os_family}}
reg_cm_solenoidui: {{ reg_cm_solenoidui }}
debug:
msg: "{{ msg.split('\n') }}"
tags: debug_info