From a2d9ffab99a7e3db833930b365c85f8dfea3c0bb Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Tue, 31 May 2022 02:14:12 +0200 Subject: [PATCH] Update tasks --- ansible/host_vars/dev-gateway0/vars.yml | 3 +++ ansible/host_vars/dev-gateway1/vars.yml | 3 +++ ansible/tasks/setup_base.yml | 2 +- ansible/tasks/setup_docker.yml | 1 + ansible/tasks/setup_sshaccess.yml | 2 +- ansible/tasks/setup_sshwifty.yml | 12 ++++++++++-- ansible/templates/Caddyfile.j2 | 2 +- 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ansible/host_vars/dev-gateway0/vars.yml b/ansible/host_vars/dev-gateway0/vars.yml index e69de29..59200b2 100644 --- a/ansible/host_vars/dev-gateway0/vars.yml +++ b/ansible/host_vars/dev-gateway0/vars.yml @@ -0,0 +1,3 @@ +--- +sshwifty_hostname: "0.0.0.0" +mongo_group_id: 0 diff --git a/ansible/host_vars/dev-gateway1/vars.yml b/ansible/host_vars/dev-gateway1/vars.yml index e69de29..fe5ae14 100644 --- a/ansible/host_vars/dev-gateway1/vars.yml +++ b/ansible/host_vars/dev-gateway1/vars.yml @@ -0,0 +1,3 @@ +--- +sshwifty_hostname: "0.0.0.0" +mongo_group_id: 1 diff --git a/ansible/tasks/setup_base.yml b/ansible/tasks/setup_base.yml index d6248d2..1daf0cc 100644 --- a/ansible/tasks/setup_base.yml +++ b/ansible/tasks/setup_base.yml @@ -3,8 +3,8 @@ - name: "Sync time - first try (needed by apt)" ansible.builtin.shell: cmd: hash ntpdate 2>/dev/null && ntpdate 0.debian.pool.ntp.org + changed_when: 'False' ignore_errors: 'yes' - no_log: 'yes' - name: Install required system packages ansible.builtin.apt: diff --git a/ansible/tasks/setup_docker.yml b/ansible/tasks/setup_docker.yml index bfa466f..c0a6fbc 100644 --- a/ansible/tasks/setup_docker.yml +++ b/ansible/tasks/setup_docker.yml @@ -34,6 +34,7 @@ - name: Get DEB architecture shell: dpkg --print-architecture register: deb_architecture + changed_when: 'False' - name: Add repository into sources list ansible.builtin.apt_repository: diff --git a/ansible/tasks/setup_sshaccess.yml b/ansible/tasks/setup_sshaccess.yml index c60b498..1824914 100644 --- a/ansible/tasks/setup_sshaccess.yml +++ b/ansible/tasks/setup_sshaccess.yml @@ -1,7 +1,7 @@ --- # Password needs to be encrypted. Use the following command to change password # python3 -c 'import crypt,getpass;pw=getpass.getpass();print(crypt.crypt(pw) if (pw==getpass.getpass("Confirm: ")) else exit())' -- name: Add the user 'debian' +- name: "Add the user '{{ sshwifty_ssh_user }}'" ansible.builtin.user: name: "{{ sshwifty_ssh_user }}" password: "{{ sshwifty_ssh_password | password_hash('sha512') }}" diff --git a/ansible/tasks/setup_sshwifty.yml b/ansible/tasks/setup_sshwifty.yml index ff1de58..6ebb9c0 100644 --- a/ansible/tasks/setup_sshwifty.yml +++ b/ansible/tasks/setup_sshwifty.yml @@ -12,16 +12,24 @@ state: directory - name: Scan SSH keys - command: "ssh-keyscan {{item}}" + shell: "ssh-keyscan -t ed25519 {{ hostvars[item]['ansible_facts']['default_ipv4']['address'] }} 2>/dev/null | ssh-keygen -lf - |cut -f2 -d' '" register: "host_keys" changed_when: false - with_items: groups["role_mongos"] + with_items: "{{ groups['role_mongo'] }}" + +- debug: + msg: "item.item={{ item.item }}, item.stdout={{ item.stdout }}" + with_items: "{{ host_keys.results }}" - name: Deploy SSHwifty configuration template: src: templates/sshwifty.conf.j2 dest: "{{ sshwifty_configuration_directory }}/sshwifty.conf" +# - name: Debug +# fail: "msg=STOP" +# when: "True" + - name: Create SSHwifty directory file: path: "{{ sshwifty_work_directory }}" diff --git a/ansible/templates/Caddyfile.j2 b/ansible/templates/Caddyfile.j2 index 80c1be1..06481c3 100644 --- a/ansible/templates/Caddyfile.j2 +++ b/ansible/templates/Caddyfile.j2 @@ -1,4 +1,4 @@ -{{ sshwifty_hostname }}:{{ sshwifty_public_port }} { +{% if sshwifty_hostname != "0.0.0.0" %}{{ sshwifty_hostname }}{% endif %}:{{ sshwifty_public_port }} { log reverse_proxy localhost:{{ sshwifty_internal_port }} {