Skip to content

Commit

Permalink
Add scenario for vagrant builder
Browse files Browse the repository at this point in the history
  • Loading branch information
msheiny committed May 7, 2018
1 parent af7c11d commit 22cd840
Show file tree
Hide file tree
Showing 17 changed files with 1,025 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,7 @@ raw-test-output/

# Ignore visual studio code folder
.vscode

#Ignore vagrant staging files
*.box
*.img
6 changes: 6 additions & 0 deletions molecule/vagrant_packager/ansible-override-vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
install_local_packages: false
primary_network_iface: eth0
ssh_users: vagrant
securedrop_app_install_from_repo: true
allow_direct_access: true
18 changes: 18 additions & 0 deletions molecule/vagrant_packager/box_files/Vagrantfile.app-staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

config.ssh.insert_key = false
config.vm.hostname = "app-staging"

config.vm.box = "bento/ubuntu-14.04"

config.vm.provider "libvirt" do |lv, override|
lv.memory = 1024
override.vm.synced_folder './', '/vagrant', type: 'nfs', disabled: false
end

config.vm.network "private_network", ip: "10.0.1.2"

end
15 changes: 15 additions & 0 deletions molecule/vagrant_packager/box_files/Vagrantfile.mon-staging
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

config.ssh.insert_key = false

config.vm.provider "libvirt" do |lv, override|
lv.memory = 1024
override.vm.synced_folder './', '/vagrant', type: 'nfs', disabled: false
end

config.vm.network "private_network", ip: "10.0.1.3"

end
20 changes: 20 additions & 0 deletions molecule/vagrant_packager/box_files/vagrant_app-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Molecule managed

---
instance:
interfaces: []
name: app-staging
raw_config_args:
- 'vm.synced_folder ''./'', ''/vagrant'', disabled: true'
- 'vm.network ''private_network'', ip: ''10.0.1.2'''
- ssh.insert_key = false
platform:
box: bento/ubuntu-14.04
box_url: null
box_version: null
provider:
name: libvirt
options:
cpus: 2
memory: 1024
raw_config_args: null
20 changes: 20 additions & 0 deletions molecule/vagrant_packager/box_files/vagrant_mon-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Molecule managed

---
instance:
interfaces: []
name: mon-staging
raw_config_args:
- 'vm.synced_folder ''./'', ''/vagrant'', disabled: true'
- 'vm.network ''private_network'', ip: ''10.0.1.3'''
- ssh.insert_key = false
platform:
box: bento/ubuntu-14.04
box_url: null
box_version: null
provider:
name: libvirt
options:
cpus: 2
memory: 1024
raw_config_args: null
Empty file.
58 changes: 58 additions & 0 deletions molecule/vagrant_packager/create.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
- import_playbook: sd_clone.yml

- name: Create
hosts: localhost
connection: local
vars:
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
molecule_instance_config: "{{ lookup('env', 'MOLECULE_INSTANCE_CONFIG') }}"
molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
tasks:

- name: Create molecule instance(s)
molecule_vagrant:
instance_name: "{{ item.name }}"
instance_interfaces: "{{ item.interfaces | default(omit) }}"
instance_raw_config_args: "{{ item.instance_raw_config_args | default(omit) }}"

platform_box: "{{ item.box }}"
platform_box_version: "{{ item.box_version | default(omit) }}"
platform_box_url: "{{ item.box_url | default(omit) }}"

provider_name: "{{ molecule_yml.driver.provider.name }}"
provider_memory: "{{ item.memory | default(omit) }}"
provider_cpus: "{{ item.cpus | default(omit) }}"
provider_raw_config_args: "{{ item.raw_config_args | default(omit) }}"
force_stop: yes

state: up
register: server
with_items: "{{ molecule_yml.platforms }}"

# Mandatory configuration for Molecule to function.

- name: Populate instance config dict
set_fact:
instance_conf_dict: {
'instance': "{{ item.Host }}",
'address': "{{ item.HostName }}",
'user': "{{ item.User }}",
'port': "{{ item.Port }}",
'identity_file': "{{ item.IdentityFile }}", }
with_items: "{{ server.results }}"
register: instance_config_dict
when: server.changed | bool

- name: Convert instance config dict to a list
set_fact:
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
when: server.changed | bool

- name: Dump instance config
copy:
# NOTE(retr0h): Workaround for Ansible 2.2.
# https://github.com/ansible/ansible/issues/20885
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool
40 changes: 40 additions & 0 deletions molecule/vagrant_packager/destroy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---

- name: Destroy
hosts: localhost
connection: local
vars:
molecule_file: "{{ lookup('env', 'MOLECULE_FILE') }}"
molecule_instance_config: "{{ lookup('env',' MOLECULE_INSTANCE_CONFIG') }}"
molecule_yml: "{{ lookup('file', molecule_file) | molecule_from_yaml }}"
molecule_ephemeral_directory: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}"
tasks:
- name: Destroy molecule instance(s)
molecule_vagrant:
instance_name: "{{ item.name }}"
platform_box: "{{ item.box }}"
provider_name: "{{ molecule_yml.driver.provider.name }}"
force_stop: "{{ item.force_stop | default(True) }}"

state: destroy
register: server
with_items: "{{ molecule_yml.platforms }}"

- name: Destroy locally cloned git folder
file:
state: absent
path: "{{ molecule_ephemeral_directory }}/sd-orig"

# Mandatory configuration for Molecule to function.

- name: Populate instance config
set_fact:
instance_conf: {}

- name: Dump instance config
copy:
# NOTE(retr0h): Workaround for Ansible 2.2.
# https://github.com/ansible/ansible/issues/20885
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}"
dest: "{{ molecule_instance_config }}"
when: server.changed | bool
Loading

0 comments on commit 22cd840

Please sign in to comment.