Skip to content

Commit

Permalink
ansible-lint added + related fixes, TravisCI improved, remote ssh ubu…
Browse files Browse the repository at this point in the history
…ntu added
  • Loading branch information
ruzickap committed Jun 22, 2018
1 parent d41fd4a commit 78ef8fc
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 11 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
sudo: required

env:
- PACKER_URL=https://releases.hashicorp.com/packer/1.2.3/packer_1.2.3_linux_amd64.zip

# Install jq
addons:
apt:
Expand All @@ -11,7 +8,7 @@ addons:

install:
- gem install awesome_bot
- sudo pip install ansible
- sudo pip install ansible ansible-lint

script:
- set -e
Expand All @@ -21,7 +18,8 @@ script:
- awesome_bot --white-list "$" --allow-dupe --allow-redirect --skip-save-results `find . -name "*.md"`
# Validate Packer templates
- |
curl $PACKER_URL --output /tmp/packer_linux_amd64.zip
PACKER_LATEST_VERSION=$(curl -s https://checkpoint-api.hashicorp.com/v1/check/packer | jq -r -M '.current_version')
curl https://releases.hashicorp.com/packer/${PACKER_LATEST_VERSION}/packer_${PACKER_LATEST_VERSION}_linux_amd64.zip --output /tmp/packer_linux_amd64.zip
sudo unzip -o /tmp/packer_linux_amd64.zip -d /usr/local/bin/
for FILE in *.json; do
echo "*** $FILE"
Expand All @@ -41,3 +39,4 @@ script:
done
# Check Ansible playbooks
- ansible-playbook -i 'localhost,' --syntax-check ansible/*.yml
- ansible-lint -x ANSIBLE0010 ansible/*.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
state: latest

- name: Check if reboot is necessary
shell: LAST_KERNEL=$(rpm -q --last kernel-core | awk 'NR==1 {sub(/kernel-core-/,""); print $1}'); CURRENT_KERNEL=$(uname -r); if [ $LAST_KERNEL != $CURRENT_KERNEL ]; then echo 'reboot'; fi
shell: if [ "$(rpm -q --last kernel-core | awk 'NR==1 {sub(/kernel-core-/,""); print $1}')" != "$(uname -r)" ]; then echo 'reboot'; fi
changed_when: false
register: reboot_out

Expand All @@ -73,7 +73,7 @@
pause:
prompt: 'Please confirm you want to reboot the remote machine: {{ ansible_host }}! Press return to continue. Press Ctrl+c and then "a" to abort'

- name: Reboot machne to boot to latest kernel
- name: Reboot machine to boot to latest kernel
shell: sleep 2 && shutdown -r now "Ansible triggered reboot"
async: 1
poll: 0
Expand Down Expand Up @@ -122,16 +122,19 @@
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]
shell: "{{ run_script }}"
command: "{{ run_script }}"
register: run_script_out
args:
chdir: "{{ build_path }}/packer-templates"
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]
shell: ./vagrant_init_destroy_boxes.sh
command: ./vagrant_init_destroy_boxes.sh
register: out
args:
chdir: "{{ build_path }}/packer-templates"
changed_when: true
117 changes: 117 additions & 0 deletions ansible/build_remote_ssh_ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
# This can be used only with latest Ubuntu
- hosts: all
gather_facts: false

vars:
build_path: /var/tmp/

packages:
- ansible
- curl
- git
- libvirt-bin
- libvirt-dev
- python-pip
- unzip
- virtualbox-qt
- wget
packer_templates_git_repo: https://github.com/ruzickap/packer-templates.git

run_script: ./build_all.sh

vagrant_plugins:
- vagrant-libvirt
- vagrant-winrm

tasks:
- name: Install Python
raw: sudo bash -x -c "test -e /usr/bin/python || test -x /usr/bin/apt && ( apt -qqy update && apt install -y python-minimal )"
register: output
changed_when: output.stdout is search("Unpacking")

- name: Gather facts
setup:

- block:
- name: Update all packages to the latest version
apt:
upgrade: dist
update_cache: yes

- name: Get latest version of Vagrant
uri:
url: https://checkpoint-api.hashicorp.com/v1/check/vagrant
return_content: yes
register: vagrant_uri

- name: Install Vagrant
apt:
deb: "https://releases.hashicorp.com/vagrant/{{ vagrant_uri.json.current_version }}/vagrant_{{ vagrant_uri.json.current_version }}_{{ ansible_architecture }}.deb"

- name: Install packages
apt:
name: "{{ item }}"
loop: "{{ packages }}"

# python-winrm for python2 is not part of ubuntu
- name: Instal pywinrm
pip:
name: pywinrm

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

- name: Get latest version of Packer
uri:
url: https://checkpoint-api.hashicorp.com/v1/check/packer
return_content: yes
register: packer_uri

- name: Download and unzip packer
unarchive:
src: "https://releases.hashicorp.com/packer/{{ packer_uri.json.current_version }}/packer_{{ packer_uri.json.current_version }}_linux_amd64.zip"
dest: /usr/local/bin/
remote_src: yes
creates: /usr/local/bin/packerio
validate_certs: false

- name: Move packer to packerio
command: mv /usr/local/bin/packer /usr/local/bin/packerio
args:
creates: /usr/local/bin/packerio
become: true

- name: List installed Vagrant Plugins
command: vagrant plugin list
register: vagrant_plugin_list
changed_when: false

- name: Install Vagrant Plugins
command: vagrant plugin install {{ item }}
loop: "{{ vagrant_plugins }}"
when: vagrant_plugin_list.stdout is not search(item)

- name: Clone the git repository
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
File renamed without changes.
13 changes: 13 additions & 0 deletions build_remote_ssh_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash -eux

REMOTE_IP="192.168.121.161"
REMOTE_USER="vagrant"

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

# Build single image - windows_10:virtualbox
#ansible-playbook -i "$REMOTE_IP," --user $REMOTE_USER --extra-vars 'run_script="./build.sh windows_10: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:virtualbox windows_10:libvirt ubuntu-server-18.04:libvirt"' ansible/build_remote_ssh.yml
3 changes: 2 additions & 1 deletion upload_all_boxes_to_vagrantup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash -eu

VAGRANT_CLOUD_USER=${VAGRANT_CLOUD_USER:-peru}
LOGFILE="vagrant_init_destroy_boxes.log"
TMPDIR="/tmp"
LOGFILE="$TMPDIR/vagrant_init_destroy_boxes.log"
export VERSION=${VERSION:-`date +%Y%m%d`.01}

(
Expand Down
2 changes: 1 addition & 1 deletion vagrant_init_destroy_boxes.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash -eu

BOXES_LIST=${*:-`find . -maxdepth 1 \( -name "*ubuntu*.box" -o -name "*centos*.box" -o -name "*windows*.box" \) -printf "%f\n" | sort | tr "\n" " "`}
TMPDIR="/tmp/"
TMPDIR="/tmp"
LOGFILE="$TMPDIR/vagrant_init_destroy_boxes.log"


Expand Down

0 comments on commit 78ef8fc

Please sign in to comment.