2023-06-12 17:03:08 -07:00
|
|
|
- name: Prepare wsl distribution to run snapd
|
|
|
|
|
hosts: commander
|
|
|
|
|
tasks:
|
|
|
|
|
# TODO the conditional should be given only once in a block
|
|
|
|
|
- name: Install Docker
|
|
|
|
|
become: true
|
|
|
|
|
apt:
|
|
|
|
|
name: docker.io
|
|
|
|
|
state: present
|
|
|
|
|
when: "ansible_os_family == 'Debian'"
|
|
|
|
|
|
|
|
|
|
- name: Start Docker service
|
|
|
|
|
become: true
|
|
|
|
|
service:
|
|
|
|
|
name: docker
|
|
|
|
|
state: started
|
|
|
|
|
when: "ansible_os_family == 'Debian'"
|
|
|
|
|
|
|
|
|
|
- name: Start Docker for Desktop
|
|
|
|
|
hosts: commander
|
|
|
|
|
gather_facts: false
|
|
|
|
|
tasks:
|
|
|
|
|
- name: Start Docker for Desktop on MacOS
|
|
|
|
|
command: open /Applications/Docker.app
|
|
|
|
|
when: ansible_os_family == "Darwin"
|
|
|
|
|
|
|
|
|
|
- name: Start the pricer container normally
|
|
|
|
|
docker_container:
|
|
|
|
|
name: pricer
|
|
|
|
|
image: dev
|
|
|
|
|
state: started
|
|
|
|
|
restart_policy: always
|
|
|
|
|
ports:
|
|
|
|
|
- "2222:22"
|
|
|
|
|
register: container
|
|
|
|
|
- debug:
|
|
|
|
|
# TODO: figure out how to extract the hostname from the above variable
|
|
|
|
|
var: "{{ container.Config.Hostname }}"
|
|
|
|
|
|
2023-06-06 17:49:59 -04:00
|
|
|
- name: Basic system checks
|
2023-06-12 17:03:08 -07:00
|
|
|
hosts: docker_container
|
2023-06-06 17:49:59 -04:00
|
|
|
tasks:
|
|
|
|
|
- name: Check to make sure the package manager is apt
|
|
|
|
|
fail:
|
|
|
|
|
msg: "Package manager is not apt"
|
|
|
|
|
when: "ansible_pkg_mgr != 'apt'"
|
2023-06-12 17:03:08 -07:00
|
|
|
|
2023-06-08 16:41:26 -04:00
|
|
|
- name: Install git
|
|
|
|
|
apt:
|
|
|
|
|
name: git
|
|
|
|
|
state: present
|
|
|
|
|
|
2023-06-13 16:44:33 -04:00
|
|
|
- name: Create /opt/pricer directory
|
|
|
|
|
file:
|
|
|
|
|
path: /opt/pricer
|
|
|
|
|
state: directory
|
|
|
|
|
mode: '0755'
|
|
|
|
|
|
2023-06-12 17:03:08 -07:00
|
|
|
- name: Check out the pricer repository
|
2023-06-07 16:12:02 -04:00
|
|
|
git:
|
|
|
|
|
repo: https://gogs.gtsplab.com:5432/SVIG/pricer.git
|
|
|
|
|
dest: /opt/pricer
|
|
|
|
|
version: main
|
2023-06-07 16:23:24 -04:00
|
|
|
|
2023-06-12 17:03:08 -07:00
|
|
|
- name: Install Python requirements setuptools + distutils + pkg-resources + pip
|
2023-06-08 16:41:26 -04:00
|
|
|
apt:
|
|
|
|
|
name:
|
|
|
|
|
- python3-setuptools
|
|
|
|
|
- python3-distutils
|
|
|
|
|
- python3-pkg-resources
|
|
|
|
|
- python3-pip
|
|
|
|
|
state: present
|
|
|
|
|
|
|
|
|
|
- name: Install the pricer Python package dependencies
|
2023-06-07 16:23:24 -04:00
|
|
|
ansible.builtin.pip:
|
|
|
|
|
requirements: /opt/pricer/requirements.txt
|
2023-06-08 16:41:26 -04:00
|
|
|
|
2023-06-12 17:03:08 -07:00
|
|
|
- name: Install Selenium
|
|
|
|
|
ansible.builtin.pip:
|
|
|
|
|
name: selenium
|
|
|
|
|
state: present
|
|
|
|
|
|
|
|
|
|
# Start the container in privileged mode with:
|
|
|
|
|
# docker run --privileged --cgroupns=host -d -v /sys/fs/cgroup:/sys/fs/cgroup:rw dev /lib/systemd/systemd
|
|
|
|
|
# systemctl start snapd
|
|
|
|
|
# systemctl start udev
|
|
|
|
|
# snap install chromium
|
|
|
|
|
# You can use ansible.community.docker to run the container, then do all the above stuff
|
|
|
|
|
# docker_container_exec might be useful
|
|
|
|
|
#
|
|
|
|
|
# Translate the docker run command into the docker_container ansible module with these args:
|
|
|
|
|
# -v | volumes:
|
|
|
|
|
# --cgroupns | cgroupns_mode:
|
|
|
|
|
# -d | detach: true
|
|
|
|
|
#
|
|
|
|
|
# 1) Start the container with systemd, so we can use snap to install packages
|
|
|
|
|
# 2) Install chromium using snap
|
|
|
|
|
# 3) Stop the container
|
|
|
|
|
# 4) Re-start the container without systemd, using the default RUN command "/usr/sbin/sshd -D"
|
|
|
|
|
# 5) Run the scraper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Start pricer container with systemd
|
|
|
|
|
hosts: commander
|
|
|
|
|
tasks:
|
|
|
|
|
- name: Run pricer container
|
|
|
|
|
docker_container:
|
|
|
|
|
# TODO: make sure to use the container id from above so you don't start another container
|
|
|
|
|
name: pricer
|
|
|
|
|
image: dev
|
|
|
|
|
state: started
|
|
|
|
|
restart_policy: always
|
|
|
|
|
volumes:
|
|
|
|
|
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
|
|
|
|
privileged: yes
|
|
|
|
|
ports:
|
|
|
|
|
- "2222:22"
|
|
|
|
|
- "9515:9515"
|
|
|
|
|
command: /lib/systemd/systemd
|
|
|
|
|
|
|
|
|
|
- name: Continue installing chromium using snap
|
|
|
|
|
hosts: docker_container
|
|
|
|
|
become: true
|
|
|
|
|
tasks:
|
|
|
|
|
- name: Start snapd and udev
|
|
|
|
|
docker_container:
|
|
|
|
|
name: pricer
|
|
|
|
|
command: systemctl start snapd udev
|
|
|
|
|
- name: Install chromium
|
|
|
|
|
docker_container:
|
|
|
|
|
name: pricer
|
|
|
|
|
command: snap install chromium
|
|
|
|
|
|
|
|
|
|
- name: Run latest version of scraper
|
|
|
|
|
hosts: docker_container
|
|
|
|
|
tasks:
|
|
|
|
|
# TODO use the ansible variable to get the home directory
|
|
|
|
|
- name: Clone pricer repository
|
|
|
|
|
git:
|
|
|
|
|
repo: https://gogs.gtsplab.com:5432/SVIG/pricer.git
|
|
|
|
|
dest: /root/pricer
|
|
|
|
|
version: master
|
|
|
|
|
- name: Run scraper
|
|
|
|
|
command: python /root/fp_merge.py
|