Set up ansible playbook

parent 4e7b8ce3
```shell
$ ansible-galaxy install -r requirements.yml
$ ansible-playbook playbook.yml
```
- name: setup-builder
hosts: builders
remote_user: "{{ login_username }}"
become: yes
become_user: root
become_method: sudo
tasks:
- name: Install sbuild
apt:
name: sbuild
state: latest
- name: Install perl datetime
apt:
name: libdatetime-format-strptime-perl
state: latest
- name: Install perl web abilities
apt:
name: libwww-perl
state: latest
- name: Install perl json
apt:
name: libjson-perl
state: latest
---
login_username: admin
build_gpg_user: foo
build_gpg_realname: "foo bar"
build_gpg_email: "foo@localhost"
main_template_enable: true
http_template_enable: true
[builders]
builder1
[visualizers]
visualizer1
\ No newline at end of file
- name: setup-reproducer
hosts: reproducer
- name: Debugging Stuff (this is needed to obtain the ipv4 addresses once)
hosts: all
tasks:
- debug: var=hostvars[inventory_hostname]['ansible_default_ipv4']['address']
- name: Setup Builders
hosts: builders
remote_user: "{{ login_username }}"
become: yes
become_user: root
become_method: sudo
vars_files:
- external_vars.yml
roles:
- builders
# The gpgkey generation role had to be disabled because it was taking a lot of time. I'm not sure we are supposed to do this.
# - { role: juju4.gpgkey_generate, gpg_user: "{{ build_gpg_user }}", gpg_realname: "{{ build_gpg_realname }}", gpg_useremail: "{{ build_gpg_email }}" , gpg_generator_user: "root" }
tasks:
- name: Install sbuild
apt:
name: sbuild
state: latest
- name: Install perl datetime
apt:
name: libdatetime-format-strptime-perl
state: latest
- name: Install perl web abilities
- name: Setup Visualizers
hosts: visualizers
remote_user: "{{ login_username }}"
become: yes
become_user: root
become_method: sudo
vars_files:
- external_vars.yml
pre_tasks:
- name: Install dirmngr for nginx
apt:
name: libwww-perl
state: latest
name: "dirmngr"
roles:
- role: nginxinc.nginx
- visualizers
- name: Install perl json
apt:
name: libjson-perl
state: latest
- src: juju4.gpgkey_generate
- src: nginxinc.nginx
- name: Install all dependencies
apt:
name: "{{ item }}"
with_items:
- sbuild
- libdatetime-format-strptime-perl
- libwww-perl
- libjson-perl
- gnupg2
- curl
- python-pip
- name: Install in-toto
pip:
name: "{{ item }}"
with_items:
- in-toto
- colorama
- name: Copy files
copy:
src: srebuild-hook
dest: /usr/lib/srebuild-hook
- name: Copy template
template:
src: srebuild.j2
dest: /usr/bin/srebuild
- name: Set permissions
file:
path: "{{ item }}"
mode: 0755
with_items:
- /usr/bin/srebuild
- /usr/lib/srebuild-hook
......@@ -226,6 +226,7 @@ sub setup_chroot_sbuild {
@repos = map { "--extra-repository=$_" } @repos;
unlink glob "/etc/schroot/chroot.d/$suite-$bn_build_root-$arch-sbuild-*";
# Setup chroot
say STDOUT "Extracting chroot";
system_fatal "mkdir", "--parents", "$build_root";
......@@ -325,7 +326,7 @@ if ( not defined($buildinfo) ) {
$buildinfo = abs_path($buildinfo);
my $temp_dir = tempdir(CLEANUP => 1);
cp( "./srebuild-hook", "$temp_dir/srebuild-hook" );
cp( "/usr/lib/srebuild-hook", "$temp_dir/srebuild-hook" );
chdir $temp_dir;
my ( $cdata, $arch, $checksums, @depends ) = parse_buildinfo $buildinfo;
......@@ -403,8 +404,8 @@ say STDOUT "starting prebuild";
system_fatal "mkdir", "--parent", "$build_root/tmp/";
cp( $buildinfo, "$build_root/tmp/$bn_buildinfo" );
cp( $buildinfo, "/tmp/$bn_buildinfo" );
cp( "./srebuild-hook", "$build_root/tmp/srebuild-hook" );
cp( "./srebuild-hook", "/tmp/srebuild-hook" );
cp( "/usr/lib/srebuild-hook", "$build_root/tmp/srebuild-hook" );
cp( "/usr/lib/srebuild-hook", "/tmp/srebuild-hook" );
say STDOUT "starting sbuild";
......@@ -447,7 +448,9 @@ say STDOUT $buildinfo_file;
system_fatal "cat", $lnk;
system_fatal "cat", $buildinfo_file;
system_fatal "curl", "-F", "metadata=\@$lnk", "-F", "buildinfo=\@$buildinfo_file", "http://ptsv2.com/t/4o082-1530243363/post";
{% for host in groups['visualizers'] %}
system_fatal "curl", "-F", "metadata=\@$lnk", "-F", "buildinfo=\@$buildinfo_file", "{{ hostvars[host]['ansible_default_ipv4']['address'] }}";
{% endfor %}
say STDOUT "everything is okay!";
......
server {
listen 80;
server_name _;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://127.0.0.1:8000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
\ No newline at end of file
[Unit]
Description=Gunicorn server for Accumulator
[Service]
WorkingDirectory=/var/accumulator
Restart=on-failure
ExecStart=/usr/local/bingunicorn --bind 127.0.0.1:4000 accumulator:app
[Install]
WantedBy=multi-user.target
\ No newline at end of file
[Unit]
Description=Gunicorn server for Visualizer
[Service]
WorkingDirectory=/var/visualizer
Restart=on-failure
ExecStart=/usr/local/bin/gunicorn --bind 127.0.0.1:8000 visualizer:app
[Install]
WantedBy=multi-user.target
CREATE TABLE BUILDS(
CREATE TABLE IF NOT EXISTS BUILDS(
source TEXT,
version TEXT,
timestamp INTEGER,
......
- name: restart gunicorn-accumulator
systemd:
name=gunicorn-accumulator
daemon_reload=yes
enabled=yes
state=restarted
- name: restart gunicorn-visualizer
systemd:
name=gunicorn-visualizer
daemon_reload=yes
enabled=yes
state=restarted
- name: Install pip
apt:
name: "{{ item }}"
with_items:
- python-pip
- sqlite3
- name: Install Python dependencies
pip:
name: "{{ item }}"
with_items:
- flask
- gunicorn
- python-debian
- name: Create necessary folders
file: path="{{ item }}" state=directory
with_items:
- /var/builds
- /var/accumulator
- /var/visualizer
- name: Copy all files
copy: src={{ item.src }} dest={{ item.dest }}
with_items:
- { src: accumulator.py, dest: /var/accumulator/accumulator.py }
- { src: visualizer.py, dest: /var/visualizer/visualizer.py }
- { src: templates, dest: /var/visualizer/ }
- { src: schema.sql, dest: /var/schema.sql }
- name: Generate DB
shell: sqlite3 /var/rebuilder.db < /var/schema.sql
- name: Run accumulator
copy: src=gunicorn-accumulator.service dest=/etc/systemd/system/gunicorn-accumulator.service
notify:
- restart gunicorn-accumulator
- name: Run visualizer
copy: src=gunicorn-visualizer.service dest=/etc/systemd/system/gunicorn-visualizer.service
notify:
- restart gunicorn-visualizer
- name: Copy nginx config
copy: src=default.conf dest=/etc/nginx/conf.d/http/default.conf
notify: "(Handler: All OSs) Reload NGINX"
flask
future
python-debian
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment