Vagrant-based testing environment #111

Merged
valberg merged 15 commits from vagrant into main 2022-11-25 13:07:10 +00:00
3 changed files with 15 additions and 30 deletions
Showing only changes of commit 6e383d6afa - Show all commits

7
Vagrantfile vendored
View file

@ -1,22 +1,29 @@
Vagrant.require_version ">= 1.7.0"
PORT = 19022
Vagrant.configure(2) do |config|
config.vm.network :forwarded_port, guest: PORT, host: PORT, id: "new_ssh"
# If we are trying to SSH into the VM, we need to use the new port
if ARGV[0] == "ssh"
config.ssh.guest_port = PORT
end
config.vm.define "datacoop" do |datacoop|
datacoop.vm.box = "ubuntu/focal64"
datacoop.vm.hostname = "datacoop"
datacoop.vm.provider "virtualbox" do |v|
v.memory = 4096
end
datacoop.vm.provision "ansible" do |ansible|
ansible.compatibility_mode = "2.0"
ansible.playbook = "playbook.yml"
ansible.ask_vault_pass = true
ansible.verbose = "v"
# If we are running the provision command, then we override the ansible_port
if ARGV[0] == "provision"
ansible.host_vars = {

View file

@ -1,5 +0,0 @@
---
- name: Restart sshd
service:
name: sshd
state: restarted

View file

@ -1,24 +1,4 @@
---
- name: Check if SSH port is already configured
wait_for:
port: 19022
host: "{{ ansible_host }}"
search_regex: "OpenSSH"
connect_timeout: 5
timeout: 10
become: false
delegate_to: localhost
ignore_errors: true
register: ssh_configured
# If running in Vagrant, ansible_port is always 2222
- name: Change Ansible port to 22 if needed
set_fact:
ansible_port: 22
when: ssh_configured is defined and
ssh_configured.state is undefined and
ansible_port != 2222
- name: Change SSH port on host
lineinfile:
dest: "/etc/ssh/sshd_config"
@ -26,13 +6,16 @@
line: "Port 19022"
register: ssh_changed
notify: "Restart sshd"
when: ssh_configured is defined and
ssh_configured.state is undefined
- name: Ensure sshd is reloaded if needed
meta: flush_handlers
- name: Restart sshd
service:
name: sshd
state: restarted
when: ssh_changed is defined and
ssh_changed.changed
- name: Change Ansible port to 19022
set_fact:
ansible_port: 19022
when: ssh_changed is defined
when: ssh_changed is defined and
ssh_changed.changed