Merged ansible playbook, re-ordered things
This commit is contained in:
+110
-15
@@ -1,34 +1,62 @@
|
||||
- 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 }}"
|
||||
|
||||
- name: Basic system checks
|
||||
hosts: all
|
||||
become: yes
|
||||
become_user: root
|
||||
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
|
||||
hosts: all
|
||||
tasks:
|
||||
|
||||
- name: Install git
|
||||
apt:
|
||||
name: git
|
||||
state: present
|
||||
|
||||
- name: Check out the pricer repository
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: Checkout pricer repository
|
||||
- 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
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: "Install setuptools + distutils + pkg-resources + pip"
|
||||
- name: Install Python requirements setuptools + distutils + pkg-resources + pip
|
||||
apt:
|
||||
name:
|
||||
- python3-setuptools
|
||||
@@ -41,3 +69,70 @@
|
||||
ansible.builtin.pip:
|
||||
requirements: /opt/pricer/requirements.txt
|
||||
|
||||
- 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
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
- name: Basic system checks
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: Check to make sure the package manager is apt
|
||||
fail:
|
||||
msg: "Package manager is not apt"
|
||||
when: "ansible_pkg_mgr != 'apt'"
|
||||
|
||||
- name: Clone pricer repository
|
||||
hosts: target_hosts
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Check out pricer repository
|
||||
git:
|
||||
repo: https://gogs.gtsplab.com:5432/SVIG/pricer.git
|
||||
dest: /Users/sloetjeswong/pricer
|
||||
|
||||
- name: Install Python requirements
|
||||
hosts: target_hosts
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Install Python requirements
|
||||
pip:
|
||||
requirements: /Users/sloetjeswong/pricer/requirements.txt
|
||||
|
||||
- name: Install Chromium and Selenium
|
||||
hosts: target_hosts
|
||||
become: yes
|
||||
tasks:
|
||||
- name: Install Chromium
|
||||
apt:
|
||||
name: chromium-browser
|
||||
state: present
|
||||
|
||||
- name: Install Selenium
|
||||
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
|
||||
|
||||
# Adds on 06/12:
|
||||
|
||||
- name: Run pricer container with systemd
|
||||
hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- name: Install Docker
|
||||
apt:
|
||||
name: docker.io
|
||||
state: present
|
||||
|
||||
- name: Start Docker service
|
||||
service:
|
||||
name: docker
|
||||
state: started
|
||||
|
||||
- name: Run pricer container
|
||||
docker_container:
|
||||
name: pricer
|
||||
image: ubuntu
|
||||
state: started
|
||||
restart_policy: always
|
||||
volumes:
|
||||
- /sys/fs/cgroup:/sys/fs/cgroup:ro
|
||||
privileged: yes
|
||||
ports:
|
||||
- "9515:9515"
|
||||
command: /sbin/init
|
||||
|
||||
- name: Start snapd and udev in the pricer container
|
||||
hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- name: Start snapd and udev
|
||||
docker_container:
|
||||
name: pricer
|
||||
command: systemctl start snapd udev
|
||||
|
||||
- name: Install chromium using snap in the pricer container
|
||||
hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- name: Install chromium
|
||||
docker_container:
|
||||
name: pricer
|
||||
command: snap install chromium
|
||||
|
||||
- name: Run latest version of scraper
|
||||
hosts: all
|
||||
become: true
|
||||
tasks:
|
||||
- name: Clone pricer repository
|
||||
git:
|
||||
repo: https://gogs.gtsplab.com:5432/SVIG/pricer.git
|
||||
dest: /Users/sloetjeswong/pricer
|
||||
version: master
|
||||
|
||||
- name: Install dependencies
|
||||
pip:
|
||||
requirements: /Users/sloetjeswong/pricer/requirements.txt
|
||||
|
||||
- name: Run scraper
|
||||
command: python /Users/sloetjeswong/pricer/fp_merge.py
|
||||
Reference in New Issue
Block a user