-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add job to build Vagrant boxes for Pulp 3
Add a new job called "pulp-3-build-box", which builds Vagrant boxes on an arbitrary host, over SSH, using Packer and Ansible. Also, uploads them to Vagrant cloud with box-name "pulp/pulpcore" for community usage. closes #2908
- Loading branch information
Ammar Ansari
committed
Feb 7, 2018
1 parent
84e6eb6
commit 7cd3e0b
Showing
17 changed files
with
499 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
- hosts: all | ||
roles: | ||
- role: pulp-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- hosts: all | ||
roles: | ||
- role: pulp-packer | ||
- role: pulp-virtualbox | ||
- role: pulp-libvirtd | ||
- role: pulp-galaxy-ansible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
- name: Update box version | ||
lineinfile: | ||
path: pulpcore.json | ||
regexp: 'version' | ||
line: "\"version\": \"{{ '%Y%m%d' | strftime }}\"" | ||
|
||
- name: Reboot Server | ||
command: /sbin/shutdown -r | ||
async: 0 | ||
poll: 0 | ||
|
||
- name: Wait for remote host to reboot | ||
wait_for_connection: | ||
delay: 60 | ||
|
||
- name: Build image | ||
command: packer build -var 'vagrant_cloud_token'={{ vagrant_cloud_token }} -force -parallel=false {{ ansible_user_dir }}/pulpcore.json | ||
async: 0 | ||
poll: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
box_name: pulp/pulpcore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
Welcome to the Pulp 3 dev environment! | ||
|
||
To get you started, we have built a nice plugin writer's guide for | ||
you - https://docs.pulpproject.org/en/3.0/nightly/plugins/plugin-writer/ and you can | ||
also ask questions in #pulp on Freenode IRC. | ||
|
||
Happy hacking, and thanks for your contribution! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
- name: Download installation playbook | ||
get_url: | ||
url: https://raw.githubusercontent.com/pulp/devel/3.0-dev/ansible/deploy-pulp3.yml | ||
dest: "{{ ansible_user_dir }}" | ||
|
||
- name: Download requirements.yml | ||
get_url: | ||
url: https://raw.githubusercontent.com/pulp/devel/3.0-dev/ansible/requirements.yml | ||
dest: "{{ ansible_user_dir }}" | ||
|
||
- name: Install ansible | ||
package: | ||
name: ansible | ||
state: installed | ||
|
||
- name: Install ansible galaxy roles | ||
command: ansible-galaxy install -r requirements.yml | ||
|
||
- name: Export motd | ||
copy: | ||
src: motd | ||
dest: "{{ ansible_user_dir }}/motd" | ||
|
||
- name: Export packer template | ||
template: | ||
src: pulpcore.json.jj2 | ||
dest: "{{ ansible_user_dir }}/pulpcore.json" |
100 changes: 100 additions & 0 deletions
100
ci/ansible/roles/pulp-galaxy-ansible/templates/pulpcore.json.jj2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{ | ||
"variables": { | ||
"vagrant_cloud_token": "" | ||
}, | ||
"builders": | ||
[ | ||
{ | ||
"type": "virtualbox-ovf", | ||
"source_path": "{{ ovf_path }}", | ||
"ssh_username": "vagrant", | ||
"ssh_password": "vagrant", | ||
"ssh_port": 22, | ||
"ssh_wait_timeout": "60s" , | ||
"headless": true, | ||
"boot_wait": "10s", | ||
{% raw %} | ||
"vboxmanage": [ | ||
["modifyvm", "{{.Name}}", "--memory", "4096"], | ||
["modifyvm", "{{.Name}}", "--natdnshostresolver1", "on"] | ||
], | ||
{% endraw %} | ||
"shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now" | ||
}, | ||
{ | ||
"type": "qemu", | ||
"accelerator": "kvm", | ||
"iso_url": "{{ img_path }}", | ||
"iso_checksum_type": "none", | ||
"qemu_binary": "qemu-kvm", | ||
"ssh_username": "vagrant", | ||
"ssh_password": "vagrant", | ||
"ssh_port": 22, | ||
"ssh_wait_timeout": "60s", | ||
"headless": true, | ||
"boot_wait": "10s", | ||
"disk_image": true, | ||
"disk_size": 40960, | ||
"qemuargs": [ | ||
[ "-m", "4096M" ] | ||
], | ||
"shutdown_command": "echo 'vagrant' | sudo -S shutdown -P now" | ||
} | ||
], | ||
"provisioners": | ||
[ | ||
{ | ||
"type": "file", | ||
"source": "motd", | ||
"destination": "/tmp/motd" | ||
}, | ||
{ | ||
"type":"shell", | ||
"only": ["virtualbox-ovf"], | ||
"inline": [ | ||
"sudo mkdir -p /tmp/vboxguest", | ||
"sudo mount -t iso9660 -o loop /home/vagrant/VBoxGuestAdditions.iso /tmp/vboxguest", | ||
"cd /tmp/vboxguest", | ||
"sudo dnf -y install dkms kernel-devel-$(uname -r) gcc", | ||
"sudo ./VBoxLinuxAdditions.run", | ||
"cd /tmp", | ||
"sudo umount /tmp/vboxguest", | ||
"sudo rmdir /tmp/vboxguest", | ||
"rm /home/vagrant/VBoxGuestAdditions.iso" | ||
] | ||
}, | ||
{ | ||
"type":"ansible", | ||
"playbook_file": "deploy-pulp3.yml", | ||
"user": "vagrant" | ||
}, | ||
{ | ||
"type":"shell", | ||
"inline": [ | ||
"sudo mv /tmp/motd /etc/motd", | ||
"sudo rm /etc/yum.repos.d/epel.repo", | ||
"sudo dnf -y install git httpie", | ||
"echo 'machine localhost' >> /home/vagrant/.netrc", | ||
"echo 'login admin' >> /home/vagrant/.netrc", | ||
"echo 'password admin' >> /home/vagrant/.netrc", | ||
"sudo sed -i 's/enforcing/permissive/' /etc/selinux/config" | ||
] | ||
} | ||
], | ||
"post-processors": | ||
[ | ||
[ | ||
{ | ||
"type": "vagrant" | ||
}, | ||
{ | ||
"type": "vagrant-cloud", | ||
{% raw %} | ||
"access_token": "{{user `vagrant_cloud_token`}}", | ||
{% endraw %} | ||
"box_tag": "{{ box_name }}", | ||
"version": "{{ '%Y%m%d' | strftime }}" | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PATH=$PATH:/usr/libexec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
- name: Install KVM and its dependencies | ||
package: | ||
name: "{{ item }}" | ||
state: present | ||
with_items: | ||
- qemu-kvm | ||
- qemu-img | ||
- virt-manager | ||
- libvirt | ||
- libvirt-python | ||
- libvirt-client | ||
- virt-install | ||
- virt-viewer | ||
- bridge-utils | ||
|
||
- name: Ensure /etc/profile.d/custom.sh exists | ||
file: | ||
path: /etc/profile.d/custom.sh | ||
state: touch | ||
|
||
- name: Add /usr/libexec to $PATH | ||
copy: | ||
dest: /etc/profile.d/custom.sh | ||
content: 'PATH=$PATH:/usr/libexec' | ||
|
||
- name: Add /usr/libexec to $PATH | ||
copy: | ||
dest: /etc/profile.d/ | ||
src: custom.sh | ||
|
||
- name: Start and enable libvirtd service | ||
systemd: | ||
name: libvirtd | ||
state: started | ||
enabled: yes | ||
|
||
- name: Get KVM status | ||
systemd: | ||
name: libvirtd | ||
register: libvirt | ||
|
||
- name: Check if kernel modules are loaded and active | ||
fail: | ||
msg: "The Kernel Modules are inactive or not loaded" | ||
when: (libvirt.status.ActiveState != 'active') or | ||
(libvirt.status.LoadState != 'loaded') | ||
|
||
- name: Add F26 libvirt box | ||
command: vagrant box add fedora/26-cloud-base --provider libvirt --force | ||
register: check_if_added | ||
until: not check_if_added | failed | ||
|
||
- name: Find img file for Fedora box | ||
find: | ||
paths: ~/.vagrant.d/boxes/fedora-VAGRANTSLASH-26-cloud-base | ||
recurse: yes | ||
patterns: 'box.img' | ||
register: results | ||
|
||
- assert: | ||
that: results['matched'] == 1 | ||
msg: "More than one .img files were found for Fedora box" | ||
|
||
- name: Set img file path | ||
set_fact: | ||
img_path: "{{ results['files'][0]['path'] }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
packer_install_directory: "/usr/local/bin" | ||
packer_version: 1.1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
- name: Check if packer is already installed | ||
stat: | ||
path: "{{ packer_install_directory }}/packer_{{ packer_version }}/packer" | ||
register: check_existing_packer | ||
|
||
- block: | ||
- name: Create packer version directory | ||
file: | ||
name: "{{ packer_install_directory }}/packer_{{ packer_version }}" | ||
state: directory | ||
|
||
- name: Download packer archive | ||
get_url: | ||
url: "https://releases.hashicorp.com/packer/{{ packer_version }}/packer_{{ packer_version }}_linux_{{ ansible_architecture|regex_replace('x86_64','amd64') }}.zip" | ||
dest: "{{ packer_install_directory }}/packer_{{ packer_version }}/" | ||
timeout: 1000 | ||
register: download_packer_archive | ||
|
||
- name: Install unzip | ||
package: | ||
name: unzip | ||
when: download_packer_archive.changed | ||
|
||
- name: Unarchive packer | ||
unarchive: | ||
src: "{{ packer_install_directory }}/packer_{{ packer_version }}/packer_{{ packer_version }}_linux_{{ ansible_architecture|regex_replace('x86_64','amd64') }}.zip" | ||
dest: "{{ packer_install_directory }}/packer_{{ packer_version }}/" | ||
remote_src: yes | ||
when: download_packer_archive.changed | ||
|
||
- name: Remove packer archive | ||
file: | ||
path: "{{ packer_install_directory }}/packer_{{ packer_version }}/packer_{{ packer_version }}_linux_{{ ansible_architecture|regex_replace('x86_64','amd64') }}.zip" | ||
state: absent | ||
|
||
when: not check_existing_packer.stat.exists | ||
|
||
- name: Symlink packer to correct version | ||
file: | ||
path: "{{ packer_install_directory }}/packer" | ||
src: "{{ packer_install_directory }}/packer_{{ packer_version }}/packer" | ||
state: link | ||
force: yes | ||
mode: 0777 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
virtualbox_repo: http://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo | ||
virtualbox_key: https://www.virtualbox.org/download/oracle_vbox.asc | ||
vagrant_url: https://releases.hashicorp.com/vagrant/2.0.1/vagrant_2.0.1_x86_64.rpm |
Oops, something went wrong.