- 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: Verify the chromium browser is running at the specified port hosts: docker_container become: true tasks: - name: install the net-tools apt: name: net-tools state: present - name: Get Chromium browser port command: netstat -tlnp | grep chromium | awk '{split($4,a,":"); print a[length(a)]}' register: chromium_port - name: Display Chromium browser port debug: var: chromium_port.stdout - name: Run latest version of scraper hosts: docker_container become: true tasks: - name: Set up Chrome options set_fact: chrome_options: - "--headless" - "--no-sandbox" - "--disable-dev-shm-usage" - name: Debug chrome_options variable debug: var: chrome_options - name: Run scraper ansible.builtin.script: script: /opt/pricer/fp2_13.py executable: /usr/bin/python3 environment: PATH: "/usr/bin/chromedriver/:{{ ansible_env.PATH }}" CHROME_OPTIONS: "{{ chrome_options | join(' ') }}"