infra-ansible

ansible script to ship alpine/ssh/wireguard

git clone https://9o.is/git/infra-ansible.git

commit abb509dee13ea7156e9aa04e5ea02bf6511d4df4
parent d27b1a75ccdf502776dcaf6767df9c2e7ca50c47
Author: Jul <jul@9o.is>
Date:   Mon, 13 May 2024 20:15:50 +0800

refactor local ssh config to a file

Diffstat:
Ahost/roles/openssh/tasks/local_ssh_config.yml | 29+++++++++++++++++++++++++++++
Mhost/roles/openssh/tasks/main.yml | 28+---------------------------
2 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/host/roles/openssh/tasks/local_ssh_config.yml b/host/roles/openssh/tasks/local_ssh_config.yml @@ -0,0 +1,29 @@ +--- +- name: Get hostname + shell: cat /etc/hostname + register: hostname + +- name: Create ssh config locally + delegate_to: localhost + become: false + file: + path: ~user/.ssh/config + owner: user + group: user + mode: '0644' + state: touch + +- name: Configure ssh locally + delegate_to: localhost + delegate_facts: true + become: false + blockinfile: + path: ~user/.ssh/config + marker: "### {mark} ansible managed {{ hostname.stdout }}" + append_newline: true + prepend_newline: true + block: | + Host {{ hostname.stdout }} + HostName {{ hostname.stdout }} + User user + Port {{ openssh_port }} diff --git a/host/roles/openssh/tasks/main.yml b/host/roles/openssh/tasks/main.yml @@ -45,32 +45,6 @@ validate: sshd -t -f %s notify: restart sshd -- name: Get hostname - shell: cat /etc/hostname - register: hostname - -- name: Create ssh config locally - delegate_to: localhost - become: false - file: - path: ~user/.ssh/config - owner: user - group: user - mode: '0644' - state: touch - - name: Configure ssh locally - delegate_to: localhost - delegate_facts: true - become: false - blockinfile: - path: ~user/.ssh/config - marker: "### {mark} ansible managed {{ hostname.stdout }}" - append_newline: true - prepend_newline: true - block: | - Host {{ hostname.stdout }} - HostName {{ hostname.stdout }} - User user - Port {{ openssh_port }} + include_tasks: local_ssh_config.yml