ansible/playbooks/update_ssh_keys.yml

34 lines
1012 B
YAML
Raw Normal View History

2024-11-14 17:02:19 +01:00
- hosts: "{{ hosts }}"
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:
url: http://192.168.77.106: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:
url: http://192.168.77.106: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:
path: "cat {{ ansible_env.HOME }}/.ssh/authorized_keys"
line: key.stdout
2024-11-14 17:32:29 +01:00
- name: Print
ansible.builtin.debug:
2024-11-14 17:36:32 +01:00
msg: "the value of foo.txt is {{ lookup('ansible.builtin.file', '/home/jd/.ssh/id_rsa.pub') }}"