Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo #14

Merged
merged 7 commits into from
Dec 11, 2024
Merged

Demo #14

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@

Vagrant.require_version ">= 2.0.0"

# Select the config file from the STAGE environment variable (dev or test)
# Define environment variables DB_PASS and SSH_PASSPHRASE for your security
$DbPass = ENV['DB_PASS'] || "your_database_password"
$SshPassphrase = ENV['SSH_PASSPHRASE'] || "KeyWillBeGeneratedWithAPassphrase"

# Select the config file from the STAGE environment variable (dev or local)
# VM Configs are loaded from json files.
$Stage = ENV['STAGE'] || "dev"

# Require JSON module
require 'json'
# Read JSON file with config details
Expand Down Expand Up @@ -77,6 +82,6 @@ Vagrant.configure(2) do |config|
end
end
end
# install
config.vm.provision "shell", privileged: false, path: "controller.sh"
# install ansible+controller in the VM
config.vm.provision "shell", privileged: false, path: "controller.sh", env: {"DB_PASS"=>$DbPass, "SSH_PASS"=>$SshPassphrase}
end
2 changes: 1 addition & 1 deletion ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ roles_path = galaxy_roles:roles
executable = /bin/bash

; set inventory here, or on the command-line when running Ansible.
; dev is for Vagrant VirtualBox on Mac
; dev is for Vagrant with Hyper-V, VMWare Desktop or VirtualBox
; local is for localhost, assuming AlmaLinux or Rocky
inventory = inventory/local/hosts

Expand Down
11 changes: 4 additions & 7 deletions controller.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash -eux
export DB_PASS=your_database_password
export SSH_PASSPHRASE=KeyWillBeGeneratedWithAPassphrase

# When this is a RHEL8 variant
# vagrant inventory, do not use for production
# Runs on a RHEL8 VM
if [ -e /etc/redhat-release ]; then
major=$(tr -dc '0-9.' < /etc/redhat-release | cut -d \. -f1)
if ((major == 8))
Expand All @@ -22,7 +20,6 @@ fi
# /etc/alternatives/pip3 will point to 3.6, ansible uses 3.12
sudo pip3.12 install jmespath
ansible --version
(git clone https://github.com/playingfield/controller.git)
(git clone https://github.com/playingfield/controller.git || /bin/true)
cd controller && source ansible.sh && ./prepare.sh
echo $DB_PASS $SSH_PASSPHRASE
./provision.yml -i inventory/local/hosts -v
./provision.yml -v -e debug=true
4 changes: 2 additions & 2 deletions provision.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

pre_tasks:
- name: Lookup DB_PASS in environment variables
when: desired_state is not defined or desired_state == 'absent'
when: desired_state == 'present'
ansible.builtin.set_fact:
check_db_pass: "{{ lookup('env', 'DB_PASS') }}"
no_log: true

- name: Assert that DB_PASS is defined
when: desired_state is not defined or desired_state == 'absent'
when: desired_state == 'present'
ansible.builtin.assert:
that:
- check_db_pass | length > 8
Expand Down