ansible/playbooks/update_ssh_keys.yml

37 lines
1.1 KiB
YAML
Raw Permalink Normal View History

2024-12-10 13:19:35 +01:00
- hosts: datacenter
2024-11-14 17:02:19 +01:00
tasks:
# Deploy SSH Key
# --
- name: Create a directory if it does not exist
ansible.builtin.file:
2024-11-14 17:34:26 +01:00
path: ~/.ssh
2024-11-14 17:02:19 +01:00
state: directory
mode: '0700'
- name: Download id_rsa
ansible.builtin.get_url:
2024-12-10 13:19:35 +01:00
url: http://192.168.77.101:48000/ssh/id_rsa
2024-11-14 17:24:28 +01:00
dest: ~/.ssh/id_rsa
2024-11-14 17:02:19 +01:00
mode: '0600'
- name: Download id_rsa.pub
ansible.builtin.get_url:
2024-12-10 13:19:35 +01:00
url: http://192.168.77.101:48000/ssh/id_rsa.pub
2024-11-14 17:24:28 +01:00
dest: ~/.ssh/id_rsa.pub
2024-11-14 17:02:19 +01:00
mode: '0600'
2024-11-14 17:40:00 +01:00
- name: get remote file contents
command: "cat {{ ansible_env.HOME }}/.ssh/id_rsa.pub"
register: key
- name: show key contents
debug:
var: key.stdout
2024-11-14 17:44:01 +01:00
- name: Ensure we have our own comment added to /etc/services
ansible.builtin.lineinfile:
2024-11-14 17:44:56 +01:00
path: "{{ ansible_env.HOME }}/.ssh/authorized_keys"
2024-11-14 17:45:22 +01:00
line: "{{ key.stdout }}"
2024-11-14 17:57:34 +01:00
create: yes
2024-11-15 12:52:38 +01:00
- name: Ensure we have our own comment added to /etc/services
ansible.builtin.lineinfile:
path: "/root/.ssh/authorized_keys"
line: "{{ key.stdout }}"
create: yes
become: true