Skip to content

Commit

Permalink
Multiply environments (#5)
Browse files Browse the repository at this point in the history
* make sure that we have varant-volume dir

* Add base for multiply environments via shell env vars

* Update readme
  • Loading branch information
b00men authored Sep 14, 2018
1 parent b3fe1ad commit 6115e83
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 53 deletions.
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@
Public configuration files and environment for testing

## Operations
`vagrang up` -- download sources, test

### Dev
`vagrang up` or `pxe_env=dev vagrang up` will download **whole** ubuntu image (~800mb) and netboot tarball if it aren't presented already.
Test server will be deployed with a PXE service, hosted preseed file and a http ubuntu mirror. This will provide a quite fast installation on test client.
A good choice to start of developing a new feature.

### Stage
`pxe_env=stage vagrang up` will download only netboot tarball if it isn't presented already.
Test server will be deployed with a PXE service but will use a global ubuntu mirror and preseed from [public gist](https://gist.github.com/b00men/40fb6781b8bc8b4d94ef15aa18c462c9). The speed of installation will depend on your connection speed.
A good choice to check changes before publishing in a repository.

### Prod
`pxe_env=prod vagrang up` will download only netboot tarball if it isn't presented already.
Test server will be deployed with a PXE service but will use a global ubuntu mirror and preseed from [repository](https://github.com/q2p-us/pxe/blob/master/preseed.txt). The speed of installation will depend on your connection speed.
A good choice to check current status on production.

## TODO
- Prepare proper test's environment
+ dev -- quick install, http based
+ stage -- gist based (https)
+ prod -- github based
+ emulation -- client will be connected to real server
- Post configuration (ipmi, ssh), take from _ks_gist.cfg_
- Move preseed to submodule
- Add COM port configuration and testing
- Default action -- boot from hdd
- Simple remote trigger to install from pxe (variable for dhcp or tftpd)
Expand Down
1 change: 1 addition & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Vagrant.configure(2) do |config|
server.vm.synced_folder "vagrant-volume/", "/vagrant-volume/"
server.vm.provision "ansible" do |ansible|
ansible.playbook = "playbook.yml"
ansible.extra_vars = { 'pxe_env': "#{ENV['pxe_env'] || "dev"}" }
end
server.vm.provider :virtualbox do |vb|
vb.memory = '1024'
Expand Down
11 changes: 8 additions & 3 deletions playbook.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
---
- hosts: all
gather_facts: False
- hosts: server
gather_facts: false
remote_user: root
become: true
roles:
- prepare

- hosts: all
- hosts: server
gather_facts: true
become: true
vars:
domain: "q2p.us"
hostname: "kem"
pxe_vagrant_ip: "192.168.2.2"
pxe_path_stage: "gist.githubusercontent.com/b00men/40fb6781b8bc8b4d94ef15aa18c462c9/raw"
pxe_path_prod: "raw.githubusercontent.com/q2p-us/pxe/master"
netboot_tar: "http://archive.ubuntu.com/ubuntu/dists/xenial-updates/main/installer-amd64/current/images/netboot/netboot.tar.gz"
iso: "http://releases.ubuntu.com/16.04/ubuntu-16.04.5-server-amd64.iso"
roles:
Expand Down
43 changes: 19 additions & 24 deletions roles/general/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
- tftp
- p7zip-full

- name: Clean netboot
- name: Ensure that necessary dirs are exists
file:
path: /vagrant-volume/netboot
state: absent
path: "/vagrant-volume/{{ item }}"
state: directory
with_items:
- netboot
- ubuntu

- name: Check netboot.tar.gz
stat:
Expand All @@ -24,43 +27,35 @@
dest: /vagrant-volume/netboot.tar.gz
when: stat_netboot_tar.stat.exists == False

- name: mkdir netboot
file:
path: /vagrant-volume/netboot
state: directory

- name: Extract netboot tarball
unarchive:
src: /vagrant-volume/netboot.tar.gz
dest: /vagrant-volume/netboot
remote_src: yes

- name: mkdir ubuntu
file:
path: /vagrant-volume/ubuntu
state: directory

- name: Check ubuntu files
stat:
path: /vagrant-volume/ubuntu/isolinux
register: stat_ubuntu
when: pxe_env == 'dev'

- name: Download ubuntu
get_url:
url: "{{ iso }}"
dest: /vagrant-volume/ubuntu.iso
when: stat_ubuntu.stat.exists == False
when: |
stat_ubuntu.stat is defined and
stat_ubuntu.stat.exists == False and
pxe_env == 'dev'
- name: Extract ubuntu # TODO: replace by mounting or extracting via iso_extract
shell: 7z x /vagrant-volume/ubuntu.iso -o/vagrant-volume/ubuntu/ && rm -rf /vagrant-volume/ubuntu.iso
when: stat_ubuntu.stat.exists == False

#- name: Copy ks.cfg
# copy:
# src: ks.cfg
# dest: /vagrant-volume/netboot/ks.cfg

- name: Copy syslinux.cfg
copy:
src: syslinux.cfg
when: |
stat_ubuntu.stat is defined and
stat_ubuntu.stat.exists == False and
pxe_env == 'dev'
- name: Generate and copy syslinux.cfg
template:
src: syslinux.cfg.j2
dest: /vagrant-volume/netboot/ubuntu-installer/amd64/boot-screens/syslinux.cfg
12 changes: 12 additions & 0 deletions roles/general/templates/syslinux.cfg.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# D-I config version 2.0
# search path for the c32 support libraries (libcom32, libutil etc.)
path ubuntu-installer/amd64/boot-screens/
default ubuntu-installer/amd64/boot-screens/vesamenu.c32
prompt 0
timeout 5

label Ubuntu16
menu default
menu LABEL Ubuntu16
kernel ubuntu-installer/amd64/linux
append initrd=ubuntu-installer/amd64/initrd.gz domain={{ domain }} hostname={{ hostname }} preseed/url={{ pxe_proto }}://{{pxe_path}}/preseed.txt mirror/http/hostname={{ pxe_mirror }} mirror/protocol={{ pxe_proto }} debian-installer/allow_unauthenticated_ssl=true locale=en_US.UTF-8 debian/priority=critical vga=normal debian-installer/keymap=us console-keymaps-at/keymap=us console-setup/layoutcode=en_US netcfg/choose_interface=auto localechooser/translation/warn-light=true localechooser/translation/warn-severe=true console-setup/ask_detect=false FRONTEND_BACKGROUND=original -
11 changes: 11 additions & 0 deletions roles/general/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

pxe_path_dev: "{{ pxe_vagrant_ip }}"
pxe_mirror_dev: "{{ pxe_vagrant_ip }}"
pxe_mirror_prod: "archive.ubuntu.com"

pxe_proto: "{% if pxe_env=='dev' %}http{% else %}https{% endif %}"
pxe_mirror: "{% if pxe_env=='dev' %}{{ pxe_mirror_dev }}{% else %}{{ pxe_mirror_prod }}{% endif %}"
pxe_path: "{% if pxe_env=='dev' %}{{ pxe_path_dev }}\
{% elif pxe_env=='stage' %}{{ pxe_path_stage }}\
{% elif pxe_env=='prod' %}{{ pxe_path_prod }}{% endif %}"
2 changes: 2 additions & 0 deletions roles/nginx/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@
state: link
owner: nobody
mode: 0777
when: pxe_env == 'dev'

# - name: Enshure that we have proper permissions for web
# file:
# path: /var/www
# recurse: true
# owner: nobody
# mode: 0777
# when: pxe_env == 'dev'

- name: Enable ip forward
sysctl:
Expand Down
11 changes: 11 additions & 0 deletions roles/prepare/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
---
- name: Fail if pxe_env is wrong
fail:
msg: "pxe_env is not defined or it's not in dev/stage/prod"
when: |
pxe_env is not defined or
(
pxe_env != 'dev' and
pxe_env != 'stage' and
pxe_env != 'prod'
)
- name: apt-get update
raw: DEBIAN_FRONTEND=noninteractive apt-get -y -q update

Expand Down
21 changes: 0 additions & 21 deletions syslinux.cfg

This file was deleted.

Empty file added vagrant-volume/.placeholder
Empty file.

0 comments on commit 6115e83

Please sign in to comment.