Skip to content

Instantly share code, notes, and snippets.

@mcrosson
Created February 10, 2015 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcrosson/b6964416ff6b0a168070 to your computer and use it in GitHub Desktop.
Save mcrosson/b6964416ff6b0a168070 to your computer and use it in GitHub Desktop.
---
- hosts: 127.0.0.1
connection: local
vars_prompt:
- name: tempdir
prompt: "Directory for temp data"
default: "/tmp/devops"
private: no
- name: bootstrap_eth_bridge
prompt: "Adapter for the Vagrant VM public adapter"
default: "en3: Thunderbolt Ethernet"
private: no
- name: bootstrap_eth_ip
prompt: "IP for the Vagrant VM"
private: no
- name: cobbler_server_ip
prompt: "IP for Cobbler server"
private: no
- name: cobbler_default_password_crypted
prompt: "Crypted password for Cobbler server"
private: yes
tasks:
- name: Setup working dir in /tmp
file: path="{{ tempdir }}" state=directory
- name: Copy Vagrantfile
template: src=roles/cobbler/templates/Vagrantfile
dest="{{ tempdir }}/Vagrantfile"
- name: Setup Vagrant provisioning directory
file: path="{{ tempdir }}/provisioning" state=directory
- name: Setup Vagrant Ansible provisioning playbook
copy: src=roles/cobbler/templates/playbook_vagrant.yml
dest="{{ tempdir }}/provisioning/vagrant.yml"
- name: Setup Cobbler Ansible role for use with Vagrant provisioning
copy: src=roles/cobbler
dest="{{ tempdir }}/provisioning/"
- name: Bring up VirtualBox VM for temp Cobbler instance
shell: vagrant up
args:
chdir: "{{ tempdir }}"
#- name: Tear down Vagrant VM
# shell: vagrant destroy
# args:
# chdir: "{{ tempdir }}"
#- name: Cleanup temp dir
# file: path="{{ tempdir }}" state=absent
---
- name: restart cobbler
service: name=cobbler state=restarted
---
- name: Install Cobbler and dependencies
action: "{{ansible_pkg_mgr}} pkg={{ item }} state=present"
with_items:
- cobbler
- debmirror
- genisoimage
- name: Setup default root password
replace: "dest=/etc/cobbler/settings
regexp='^default_password_crypted: \"\"'
replace='default_password_crypted: \"{{ cobbler_default_password_crypted }}\"'"
notify: restart cobbler
- name: Set server IP
replace: "dest=/etc/cobbler/settings
regexp='^server: (.*)'
replace='server: {{ cobbler_server_ip }}'"
- name: Set Cobbler service to enabled
service: name=cobbler enabled=yes
- name: Run initial Cobbler sync
shell: cobbler sync
- name: Download Cobbler boot loaders
shell: cobbler get-loaders
- name: Create ISO download directory
file: path=/opt/iso state=directory
owner=root group=root mode=0770
- name: Download Ubuntu 14.04 LTS (amd64) ISO (this may take awhile)
get_url: url=http://releases.ubuntu.com/14.04.1/ubuntu-14.04.1-server-amd64.iso
dest=/opt/iso
- name: Mount Ubuntu 14.04 LTS ISO For Import into Cobbler
shell: mount -t iso9660 -o loop,ro /opt/iso/ubuntu-14.04.1-server-amd64.iso /mnt
- name: Import Ubuntu 14.04 LTS into Cobbler
shell: cobbler import --name=ubuntu1404 --arch=x86_64 --path=/mnt
- name: Unmount Ubuntu 14.04 LTS ISO
shell: umount /mnt
# !!!!!! The Ubuntu repo's are HUGE -- Don't mirror for the boot strap via Vagrant -- Consider doing this once 5-10 hosts / VMs come online as part of production deployment
#- name: Sync Cobbler repo's (this will take awhile)
# shell: cobbler reposync
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "ubuntu/trusty64"
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
config.vm.network "public_network",
bridge: "{{ bootstrap_eth_bridge }}",
ip: "{{ bootstrap_eth_ip }}"
# Setup Ansible provisioning
# https://docs.vagrantup.com/v2/provisioning/ansible.html
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provisioning/vagrant.yml"
ansible.sudo = true
#ansible.verbose = "vv"
ansible.extra_vars = {
cobbler_server_ip: "{{ cobbler_server_ip }}",
cobbler_default_password_crypted: "{{ cobbler_default_password_crypted }}"
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment