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
52ead4fee5
commit
b56690a33e
3
Vagrantfile
vendored
3
Vagrantfile
vendored
|
@ -1,14 +1,13 @@
|
||||||
Vagrant.require_version ">= 1.7.0"
|
Vagrant.require_version ">= 1.7.0"
|
||||||
|
|
||||||
Vagrant.configure(2) do |config|
|
Vagrant.configure(2) do |config|
|
||||||
|
config.vm.network "forwarded_port", guest: 19022, host: 19022, id: "new_ssh"
|
||||||
config.vm.define "datacoop" do |datacoop|
|
config.vm.define "datacoop" do |datacoop|
|
||||||
datacoop.vm.box = "ubuntu/bionic64"
|
datacoop.vm.box = "ubuntu/bionic64"
|
||||||
datacoop.vm.hostname = "datacoop"
|
datacoop.vm.hostname = "datacoop"
|
||||||
datacoop.vm.provider "virtualbox" do |v|
|
datacoop.vm.provider "virtualbox" do |v|
|
||||||
v.memory = 4096
|
v.memory = 4096
|
||||||
end
|
end
|
||||||
datacoop.vm.network "private_network", ip: "192.168.0.42"
|
|
||||||
datacoop.vm.provision "ansible" do |ansible|
|
datacoop.vm.provision "ansible" do |ansible|
|
||||||
ansible.verbose = "v"
|
ansible.verbose = "v"
|
||||||
ansible.compatibility_mode = "2.0"
|
ansible.compatibility_mode = "2.0"
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- nginx-proxy
|
- nginx-proxy
|
||||||
|
- postfix
|
||||||
- openldap
|
- openldap
|
||||||
- nextcloud
|
- nextcloud
|
||||||
- passit
|
- passit
|
||||||
- gitea
|
- gitea
|
||||||
- postfix
|
|
||||||
- matrix_riot
|
- matrix_riot
|
||||||
- privatebin
|
- privatebin
|
||||||
- codimd
|
- 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
|
|
@ -4,17 +4,19 @@
|
||||||
name: "{{ packages }}"
|
name: "{{ packages }}"
|
||||||
vars:
|
vars:
|
||||||
packages:
|
packages:
|
||||||
- aptitude
|
- aptitude
|
||||||
- python3-pip
|
- python3-pip
|
||||||
- apparmor
|
- apparmor
|
||||||
- haveged
|
- haveged
|
||||||
- mosh
|
- mosh
|
||||||
- srvadmin-all # Dell OpenManage
|
- srvadmin-all # Dell OpenManage
|
||||||
|
|
||||||
- name: Install necessary packages via pip
|
- name: Install necessary packages via pip
|
||||||
pip:
|
pip:
|
||||||
name: "{{ packages }}"
|
name: "{{ packages }}"
|
||||||
|
state: latest
|
||||||
vars:
|
vars:
|
||||||
packages:
|
packages:
|
||||||
|
- pip # upgrade needed for docker-compose to install
|
||||||
- docker
|
- docker
|
||||||
- docker-compose
|
- docker-compose
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
---
|
---
|
||||||
|
- import_tasks: ssh.yml
|
||||||
|
tags: [change-ssh-port]
|
||||||
- import_tasks: custom-apt-repos.yml
|
- import_tasks: custom-apt-repos.yml
|
||||||
tags: [setup-custom-apt]
|
tags: [setup-custom-apt]
|
||||||
- import_tasks: upgrade.yml
|
- import_tasks: upgrade.yml
|
||||||
|
@ -7,4 +9,3 @@
|
||||||
tags: [install-base-packages]
|
tags: [install-base-packages]
|
||||||
- import_tasks: users.yml
|
- import_tasks: users.yml
|
||||||
tags: [setup-users]
|
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