Files
pricer/basic_checks.yml
T

174 lines
4.5 KiB
YAML

- 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: Install requests module
pip:
name: requests
state: present
- name: Start the pricer container normally
docker_container:
name: loving_benz
image: dev
state: started
restart_policy: always
ports:
- "2222:22"
register: container
- name: Debug container Config.Hostname
debug:
var: container.Config.Hostname
- name: Basic system checks
hosts: docker_container
tasks:
- name: Check to make sure the package manager is apt
fail:
msg: "Package manager is not apt"
when: "ansible_pkg_mgr != 'apt'"
- name: Install git
apt:
name: git
state: present
- name: Create /opt/pricer directory
file:
path: /opt/pricer
state: directory
mode: '0755'
- name: Check out the pricer repository
git:
repo: https://gogs.gtsplab.com:5432/SVIG/pricer.git
dest: /opt/pricer
version: main
- name: Install Python requirements setuptools + distutils + pkg-resources + pip
apt:
name:
- python3-setuptools
- python3-distutils
- python3-pkg-resources
- python3-pip
state: present
- name: Install the pricer Python package dependencies
ansible.builtin.pip:
requirements: /opt/pricer/requirements.txt
- name: Install Selenium
ansible.builtin.pip:
name: selenium
state: present
# Install snapd here
# 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: loving_benz
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: Install requests module
pip:
name: requests
state: present
- name: Install snapd package
apt:
name: snapd
state: present
- name: Start udev
systemd:
name: udev
state: started
- name: Start snapd
systemd:
name: snapd.service
# Verify the exact name of the systemd service for snapd using `systemctl list-unit-files | grep snapd` on the host
state: started
- name: Install chromium
snap:
name: chromium
state: present
- name: Install Chromium and Chromedriver
hosts: docker_container
become: true
tasks:
- name: Install chromium-chromedriver package
apt:
name: chromium-chromedriver
state: present
- name: Install chromium-browser package
apt:
name: chromium-browser
state: present
- name: Run latest version of scraper
hosts: docker_container
become: true
tasks:
- name: Run scraper
command: python3 /opt/pricer/fp_merge.py