Skip to content

Commit

Permalink
Add Vagrantfile and subman-devel ansible role
Browse files Browse the repository at this point in the history
See README.md for more information.

It should be possible to use the subman-devel role to configure one's
own host for development work as well, though that can be handled
outside of this commit.
  • Loading branch information
kahowell committed May 8, 2017
1 parent a9ac9cd commit 07370d5
Show file tree
Hide file tree
Showing 9 changed files with 297 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ dist
.cproject
.project
.settings
*.retry
.vagrant
7 changes: 0 additions & 7 deletions README

This file was deleted.

38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
subscription-manager
====================

The Subscription Manager package provides programs and libraries
to allow users to manage subscriptions and yum repositories
from the Candlepin.

- http://candlepinproject.org/
- https://fedorahosted.org/subscription-manager/
- https://github.com/candlepin/subscription-Manager

Vagrant
-------

`vagrant up` can be used to spin up various VMs set up for development work.
These VMs are all configured using the included ansible role "subman-devel".
The `PYTHONPATH` and `PATH` inside these environments is modified so that
running `subscription-manager` or `subscription-manager-gui` will use
scripts and modules from the source code.

Currently, the source is set up as a vagrant shared folder using rsync. This
means that it is necessary to use `vagrant rsync` to sync changes with the
host if desired.

The ansible role that provisions the VMs tries to find the IP address of
candlepin.example.com, so if the candlepin vagrant image is started first,
then the box can resolve it. (If it is started later, `vagrant provision` can
be used to update the VM's `hosts` file).

Additionally, the `Vagrantfile` is set up for sharing base VMs with
[katello/forklift](https://github.com/theforeman/forklift). Specifically,
forklift plugins can be added to a subscription-manager checkout beneath
`vagrant/plugins`in order to provide additional base images.

If RHEL-based images are added, then the Vagrantfile uses the values of
`SUBMAN_RHSM_USERNAME`, `SUBMAN_RHSM_PASSWORD`, and `SUBMAN_RHSM_HOSTNAME`
to register and auto-attach during provisioning (best done in `.bashrc` or
similar).
85 changes: 85 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

require 'yaml'

VAGRANTFILE_DIR = File.dirname(__FILE__)

Vagrant.configure("2") do |config|
vm_boxes = {
"centos7" => "centos/7",
"centos6" => "centos/6",
"fedora25" => "fedora/25-cloud-base",
}

extra_boxes_loaded = false

# allows us to share base boxes with Katello/forklift
base_boxes = Dir.glob "#{VAGRANTFILE_DIR}/plugins/*/base_boxes.yaml"
base_boxes.each do |file|
boxes = YAML.load_file(file)
boxes.each do |name, config|
if config.has_key? 'libvirt' and not name.include? 'sat'
vm_boxes[name] = config['libvirt']
extra_boxes_loaded = true
end
end
end

primary_vm = "centos7"

config.vm.provider "libvirt" # prefer libvirt

# forward X11 by default
config.ssh.forward_x11 = true

# setup shared folder
config.vm.synced_folder ".", "/vagrant", type: "rsync"

# Set up the hostmanager plugin to automatically configure host & guest hostnames
if Vagrant.has_plugin?("vagrant-hostmanager")
config.hostmanager.enabled = true
config.hostmanager.manage_host = true
config.hostmanager.manage_guest = true
config.hostmanager.include_offline = true
end

vm_boxes.each do |name, box|
is_primary = name == primary_vm
config.vm.define name, autostart: is_primary, primary: is_primary do |host|
host.vm.host_name = "#{name}.subman.example.com"
host.vm.box = box
host.vm.provider :libvirt do |domain|
domain.graphics_type = "spice"
domain.video_type = "qxl"
end
end
end

['SUBMAN_RHSM_USERNAME', 'SUBMAN_RHSM_PASSWORD', 'SUBMAN_RHSM_HOSTNAME'].each do |var|
if extra_boxes_loaded and not ENV.include? var
puts "#{var} not defined. Expect failures. Please set up environment accordingly, and run `vagrant provision`. to correct"
end
end

config.vm.provision "ansible", run: "always" do |ansible|
ansible.playbook = "vagrant/vagrant.yml"
ansible.extra_vars = {
"subman_checkout_dir" => "/vagrant",
"subman_setup_hacking_environment" => "true",
"subman_add_vagrant_candlepin_to_hosts" => "true",
}
# This will pass any environment variables beginning with "SUBMAN_" or
# "subman_" (less the prefix) along with their values to ansible for
# use in our playbooks.
#
# Check the playbooks to see how these variables are used.
env_prefix = "subman_"
ENV.each do |key, value|
if key.downcase.start_with?(env_prefix)
new_var_key = key.downcase()
ansible.extra_vars[new_var_key] = value
end
end
end
end
1 change: 1 addition & 0 deletions vagrant/plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
4 changes: 4 additions & 0 deletions vagrant/roles/subman-devel/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
subman_checkout_dir: .
subman_setup_hacking_environment: false
subman_add_vagrant_candlepin_to_hosts: false
143 changes: 143 additions & 0 deletions vagrant/roles/subman-devel/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
---
# workaround for https://github.com/ansible/ansible/pull/24179
# FIXME remove when possible
- name: configure rhsm hostname (rhel only)
command: "subscription-manager config --server.hostname {{ subman_rhsm_hostname }}"
become: yes
when: subman_rhsm_username is defined and ansible_distribution == 'RedHat'

- name: register and attach using installed subscription-manager (rhel only)
redhat_subscription:
username: "{{ subman_rhsm_username }}"
password: "{{ subman_rhsm_password }}"
server_hostname: "{{ subman_rhsm_hostname }}"
autosubscribe: yes
become: yes
when: subman_rhsm_username is defined and ansible_distribution == 'RedHat'

- name: install epel (centos)
yum:
name: epel-release
state: present
become: yes
when: ansible_distribution == 'CentOS'

- name: install epel (rhel)
yum:
name: "https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm"
state: present
become: yes
when: ansible_distribution == 'RedHat'

- name: enable optional repos (rhel only)
command: "subscription-manager repos --enable rhel-{{ ansible_distribution_major_version }}-server-optional-rpms"
become: yes
when: ansible_distribution == 'RedHat'

- name: install non-pip/spec deps
package:
name: "{{ item }}"
state: present
become: yes
with_items:
- tito
- git
- gcc
- make
- python-pip
- m2crypto
- python-ethtool
- librsvg2
- libxslt-devel
- dbus-x11
- python-dmidecode
- libselinux-python
- xorg-x11-server-Xvfb
- yum-utils

- name: install deps for subscription-manager-gui (el6 only)
yum:
name: "{{ item }}"
state: present
become: yes
with_items:
- pygtk2-libglade
- gnome-icon-theme
- usermode-gtk
when: ansible_distribution_major_version == "6"

- name: install subscription-manager build deps
command: yum-builddep -y {{ subman_checkout_dir }}/subscription-manager.spec
become: yes

- name: install python-rhsm build deps
command: yum-builddep -y {{ subman_checkout_dir }}/python-rhsm/python-rhsm.spec
become: yes

- name: install python test deps
pip:
requirements: test-requirements.txt
chdir: "{{ subman_checkout_dir }}"
become: yes

- name: build python-rhsm
command: python setup.py build_ext --inplace
args:
chdir: "{{ subman_checkout_dir }}/python-rhsm"
when: subman_setup_hacking_environment

- name: tito build & install python-rhsm (initial)
command: tito build --test --rpm --install
args:
chdir: "{{ subman_checkout_dir }}/python-rhsm"
creates: /usr/lib*/python*/site-packages/subscription_manager
when: subman_setup_hacking_environment

- name: tito build subscription-manager (initial)
command: tito build --test --rpm
args:
chdir: "{{ subman_checkout_dir }}"
creates: /usr/lib*/python*/site-packages/subscription_manager
when: subman_setup_hacking_environment

- name: install subscription-manager (initial)
shell: yum install -y /tmp/tito/*/subscription-manager-[0-9]*
args:
chdir: "{{ subman_checkout_dir }}"
creates: /usr/lib*/python*/site-packages/subscription_manager
become: yes
when: subman_setup_hacking_environment

- name: alter PATH
template:
src: subman_devel.sh.j2
dest: /etc/profile.d/subman_devel.sh
become: yes

- name: alter PYTHONPATH
lineinfile:
name: /etc/environment
line: "PYTHONPATH={{ subman_checkout_dir }}/src:{{ subman_checkout_dir }}/python-rhsm/src"
become: yes

- name: set GTK version
lineinfile:
name: /etc/environment
line: "SUBMAN_GTK_VERSION={% if ansible_distribution_major_version == '6' %}2{% else %}3{% endif %}"
become: yes

- name: configure sudo to allow sudo subscription-manager to work as expected
lineinfile:
name: /etc/sudoers
line: "Defaults secure_path = {{ subman_checkout_dir }}/bin:/sbin:/bin:/usr/sbin:/usr/bin"
regexp: '^Defaults\s+secure_path.*'
become: yes

- name: add candlepin.example.com to hosts (using this host as reference)
lineinfile:
name: /etc/hosts
line: "{{ lookup('pipe', 'resolveip -s candlepin.example.com') }} candlepin.example.com"
regexp: 'candlepin.example.com'
become: yes
ignore_errors: yes
when: subman_add_vagrant_candlepin_to_hosts
1 change: 1 addition & 0 deletions vagrant/roles/subman-devel/templates/subman_devel.sh.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PATH={{ subman_checkout_dir }}/bin:/usr/bin:/bin
23 changes: 23 additions & 0 deletions vagrant/vagrant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
- hosts: "*fedora*"
gather_facts: no
tasks:
- name: install libs so we can use ansible (fedora only)
raw: sudo yum install -y python python2-dnf

- hosts: all
roles:
- subman-devel

- hosts: all
gather_facts: no
become: yes
tasks:
- name: link vagrant's Xauthority to root user
file:
src: /home/vagrant/.Xauthority
dest: /root/.Xauthority
owner: root
group: root
state: link
force: yes

0 comments on commit 07370d5

Please sign in to comment.