Make Ansible setup testable in Vagrant
Added logic to change the sshd port if not already configured, configued Vagrantfile to work properly and fixed a couple of deploy errors.
This commit is contained in:
parent
5b2e2c0f60
commit
6a16328b7b
3
Vagrantfile
vendored
3
Vagrantfile
vendored
|
@ -1,14 +1,13 @@
|
|||
Vagrant.require_version ">= 1.7.0"
|
||||
|
||||
Vagrant.configure(2) do |config|
|
||||
|
||||
config.vm.network "forwarded_port", guest: 19022, host: 19022, id: "new_ssh"
|
||||
config.vm.define "datacoop" do |datacoop|
|
||||
datacoop.vm.box = "ubuntu/bionic64"
|
||||
datacoop.vm.hostname = "datacoop"
|
||||
datacoop.vm.provider "virtualbox" do |v|
|
||||
v.memory = 4096
|
||||
end
|
||||
datacoop.vm.network "private_network", ip: "192.168.0.42"
|
||||
datacoop.vm.provision "ansible" do |ansible|
|
||||
ansible.verbose = "v"
|
||||
ansible.compatibility_mode = "2.0"
|
||||
|
|
|
@ -9,11 +9,11 @@
|
|||
|
||||
services:
|
||||
- nginx-proxy
|
||||
- postfix
|
||||
- openldap
|
||||
- nextcloud
|
||||
- passit
|
||||
- gitea
|
||||
- postfix
|
||||
- matrix_riot
|
||||
- privatebin
|
||||
- codimd
|
||||
|
|
5
roles/ubuntu_base/handlers/main.yml
Normal file
5
roles/ubuntu_base/handlers/main.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
- name: Restart sshd
|
||||
service:
|
||||
name: sshd
|
||||
state: restarted
|
|
@ -14,7 +14,9 @@
|
|||
- name: Install necessary packages via pip
|
||||
pip:
|
||||
name: "{{ packages }}"
|
||||
state: latest
|
||||
vars:
|
||||
packages:
|
||||
- pip # upgrade needed for docker-compose to install
|
||||
- docker
|
||||
- docker-compose
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
---
|
||||
- import_tasks: ssh.yml
|
||||
tags: [change-ssh-port]
|
||||
- import_tasks: custom-apt-repos.yml
|
||||
tags: [setup-custom-apt]
|
||||
- import_tasks: upgrade.yml
|
||||
|
@ -7,4 +9,3 @@
|
|||
tags: [install-base-packages]
|
||||
- import_tasks: users.yml
|
||||
tags: [setup-users]
|
||||
|
||||
|
|
42
roles/ubuntu_base/tasks/ssh.yml
Normal file
42
roles/ubuntu_base/tasks/ssh.yml
Normal file
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
- name: Check if SSH port is already configured
|
||||
wait_for:
|
||||
port: 19022
|
||||
state: started
|
||||
host: "{{ inventory_hostname }}"
|
||||
connect_timeout: 5
|
||||
timeout: 10
|
||||
become: false
|
||||
delegate_to: localhost
|
||||
ignore_errors: true
|
||||
register: ssh_configured
|
||||
|
||||
# If we're running in Vagrant, ansible_port is 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 or
|
||||
(ssh_configured.state is defined and
|
||||
ssh_configured.state != "started")) and
|
||||
ansible_port != 2222
|
||||
|
||||
- name: Change SSH port
|
||||
lineinfile:
|
||||
dest: "/etc/ssh/sshd_config"
|
||||
regexp: "^#?Port"
|
||||
line: "Port 19022"
|
||||
register: ssh_changed
|
||||
notify: "Restart sshd"
|
||||
when: ssh_configured is defined and
|
||||
(ssh_configured.state is undefined or
|
||||
(ssh_configured.state is defined and
|
||||
ssh_configured.state != "started"))
|
||||
|
||||
- name: Ensure sshd is reloaded if needed
|
||||
meta: flush_handlers
|
||||
|
||||
- name: Change ansible_port 19022
|
||||
set_fact:
|
||||
ansible_port: 19022
|
||||
when: ssh_changed is defined
|
Loading…
Reference in a new issue