From 9a5d780f2b156d6d9277b083ca456841689deb48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Thu, 17 Nov 2022 08:53:45 +0100 Subject: [PATCH] Keep ansible "clean" and do ssh port magic in Vagrantfile. --- Vagrantfile | 16 ++++++++++++++-- playbook.yml | 15 ++++----------- roles/ssh_and_vagrant/tasks/main.yml | 5 ----- roles/ssh_and_vagrant/tasks/virtualization.yml | 4 ---- .../handlers/main.yml | 0 roles/ubuntu_base/tasks/main.yml | 6 ++++++ .../tasks/ssh-port.yml | 0 7 files changed, 24 insertions(+), 22 deletions(-) delete mode 100644 roles/ssh_and_vagrant/tasks/main.yml delete mode 100644 roles/ssh_and_vagrant/tasks/virtualization.yml rename roles/{ssh_and_vagrant => ubuntu_base}/handlers/main.yml (100%) rename roles/{ssh_and_vagrant => ubuntu_base}/tasks/ssh-port.yml (100%) diff --git a/Vagrantfile b/Vagrantfile index 5db0681..391209e 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,7 +1,11 @@ Vagrant.require_version ">= 1.7.0" - +PORT = 19022 Vagrant.configure(2) do |config| - config.vm.network "forwarded_port", guest: 19022, host: 19022, id: "new_ssh" + 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" @@ -13,6 +17,14 @@ Vagrant.configure(2) do |config| 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 = { + "datacoop" => { + "ansible_port" => PORT + } + } + end end end end diff --git a/playbook.yml b/playbook.yml index a9d41de..ba93281 100644 --- a/playbook.yml +++ b/playbook.yml @@ -1,12 +1,15 @@ --- - hosts: all - gather_facts: false + gather_facts: true become: true vars: base_domain: data.coop letsencrypt_email: admin@data.coop ldap_dn: "dc=data,dc=coop" + vagrant: "{{ ansible_virtualization_role == 'guest' }}" + letsencrypt_enabled: "{{ not vagrant }}" + services: - nginx-proxy - postfix @@ -33,19 +36,9 @@ smtp_port: "587" tasks: - - import_role: - name: ssh_and_vagrant - tags: - - base_only - - setup_services - import_role: name: ubuntu_base - vars: - vagrant: "{{ ansible_virtualization_role == 'guest' }}" tags: - base_only - import_role: name: docker - vars: - vagrant: "{{ ansible_virtualization_role == 'guest' }}" - letsencrypt_enabled: "{{ not vagrant }}" diff --git a/roles/ssh_and_vagrant/tasks/main.yml b/roles/ssh_and_vagrant/tasks/main.yml deleted file mode 100644 index 294e74f..0000000 --- a/roles/ssh_and_vagrant/tasks/main.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- import_tasks: ssh-port.yml - tags: [change-ssh-port] -- import_tasks: virtualization.yml - tags: [gather-virtualization-facts] diff --git a/roles/ssh_and_vagrant/tasks/virtualization.yml b/roles/ssh_and_vagrant/tasks/virtualization.yml deleted file mode 100644 index 19883e4..0000000 --- a/roles/ssh_and_vagrant/tasks/virtualization.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -- name: Determine if running in Vagrant - setup: - gather_subset: virtualization_role diff --git a/roles/ssh_and_vagrant/handlers/main.yml b/roles/ubuntu_base/handlers/main.yml similarity index 100% rename from roles/ssh_and_vagrant/handlers/main.yml rename to roles/ubuntu_base/handlers/main.yml diff --git a/roles/ubuntu_base/tasks/main.yml b/roles/ubuntu_base/tasks/main.yml index 2416ea1..3b7b4a6 100644 --- a/roles/ubuntu_base/tasks/main.yml +++ b/roles/ubuntu_base/tasks/main.yml @@ -1,10 +1,16 @@ --- +- import_tasks: ssh-port.yml + tags: [change-ssh-port] + - import_tasks: dell-apt-repo.yml tags: [setup-dell-apt-repo] when: not vagrant + - import_tasks: upgrade.yml tags: [do-full-system-upgrade] + - import_tasks: base.yml tags: [install-base-packages] + - import_tasks: users.yml tags: [setup-users] diff --git a/roles/ssh_and_vagrant/tasks/ssh-port.yml b/roles/ubuntu_base/tasks/ssh-port.yml similarity index 100% rename from roles/ssh_and_vagrant/tasks/ssh-port.yml rename to roles/ubuntu_base/tasks/ssh-port.yml