Skip to content

Commit

Permalink
Rewrite of scripts/playbook for preparing remote machines for builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzickap committed Feb 22, 2019
1 parent f8730db commit 60bb752
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
55 changes: 36 additions & 19 deletions ansible/build_remote_ssh_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
packages:
- ansible
- curl
- docker.io
- git
- gitlab-runner
- jq
- libvirt-bin
- libvirt-dev
- python-pip
Expand All @@ -18,8 +21,6 @@
- wget
packer_templates_git_repo: https://github.com/ruzickap/packer-templates.git

run_script: ./build_all.sh

vagrant_plugins:
- vagrant-libvirt
- vagrant-winrm
Expand Down Expand Up @@ -53,6 +54,11 @@
register: result
until: result is succeeded

- name: Add GitLab’s official repository
shell: curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
args:
creates: /etc/apt/sources.list.d/runner_gitlab-runner.list

- name: Install packages
apt:
name: "{{ item }}"
Expand All @@ -67,12 +73,27 @@
register: result
until: result is succeeded

- name: Add the current user "{{ ansible_user_id }}" to kvm group
- name: Add the current user "{{ ansible_user_id }}" to docker and libvirt group
user:
name: "{{ ansible_user_id }}"
groups: kvm
groups: docker,kvm,libvirt
append: yes

- name: Add the gitlab-runner user to docker and libvirt group
user:
name: gitlab-runner
groups: docker,kvm,libvirt
append: yes

# Yhis is not needed for Fedora, because in Fedora it's "crw-rw-rw- 1 root kvm 10, 232 Feb 13 09:58 /dev/kvm"
- name: Chnage righs for /dev/kvm
blockinfile:
path: /etc/udev/rules.d/60-qemu-system-common.rules
create: yes
block: |
# Chnaging rights of /dev/kvm from 0660 to 0666
KERNEL=="kvm", GROUP="kvm", MODE="0666"
- name: Get latest version of Packer
uri:
url: https://checkpoint-api.hashicorp.com/v1/check/packer
Expand All @@ -91,6 +112,17 @@
command: mv /usr/local/bin/packer /usr/local/bin/packerio
args:
creates: /usr/local/bin/packerio

- name: Remove configuration of unix socket for libvirt (/var/run/libvirt/libvirt-sock)
replace:
path: /etc/libvirt/libvirtd.conf
# Commend all lines beginning with "unix_sock_"
regexp: '^unix_sock_.*'
replace: '#&'
backup: yes

- name: Reboot the machine to use new kernel
reboot:
become: true

- name: List installed Vagrant Plugins
Expand All @@ -107,19 +139,4 @@
git:
repo: "{{ packer_templates_git_repo }}"
dest: "{{ build_path }}/packer-templates"
version: latest
force: yes

- name: Execute script to build boxes (this step usually takes long time) [for more details check *.log in /var/tmp/packer]
command: "{{ run_script }}"
args:
chdir: "{{ build_path }}/packer-templates"
register: run_script_out
changed_when: true

- name: Run vagrant_init_destroy_boxes.sh script to test all previously created box images (this step usually takes long time) [for more details check /tmp/vagrant_init_destroy_boxes.log]
command: ./vagrant_init_destroy_boxes.sh
args:
chdir: "{{ build_path }}/packer-templates"
register: vagrant_init_destroy_boxes_out
changed_when: true
12 changes: 3 additions & 9 deletions build_remote_ssh_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#!/bin/bash -eux

REMOTE_IP="192.168.121.161"
REMOTE_USER="vagrant"
REMOTE_IP="172.16.246.243,172.16.242.252,172.16.241.47"
REMOTE_USER="ubuntu"

# Build ALL images (this takes several hours)
# Prepare remote machine for build
ansible-playbook -i "$REMOTE_IP," --user $REMOTE_USER ansible/build_remote_ssh_ubuntu.yml

# Build single image - windows-10-enterprise-x64-eval-virtualbox
#ansible-playbook -i "$REMOTE_IP," --user $REMOTE_USER --extra-vars 'run_script="./build.sh windows-10-enterprise-x64-eval-virtualbox"' ansible/build_remote_ssh.yml

# Build multiple images - windows_10 (virtualbox, libvirt) and ubuntu-server-18.04 (libvirt)
#ansible-playbook -i "$REMOTE_IP," --user $REMOTE_USER --extra-vars 'run_script="./build.sh windows-10-enterprise-x64-eval-virtualbox windows-10-enterprise-x64-eval-libvirt ubuntu-18.04-server-amd64-libvirt"' ansible/build_remote_ssh.yml

0 comments on commit 60bb752

Please sign in to comment.