mirror of
				https://gitlab.sectorq.eu/jaydee/ansible.git
				synced 2025-10-30 18:01:11 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			YAML
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			YAML
		
	
	
		
			Executable File
		
	
	
	
	
| - hosts: datacenter
 | |
|   tasks:
 | |
|   # Deploy SSH Key
 | |
|   # --
 | |
|   - name: Create a directory if it does not exist
 | |
|     ansible.builtin.file:
 | |
|       path: ~/.ssh
 | |
|       state: directory
 | |
|       mode: '0700'
 | |
|   - name: Download id_rsa
 | |
|     ansible.builtin.get_url:
 | |
|       url: http://192.168.77.238:48000/ssh/id_rsa
 | |
|       dest: ~/.ssh/id_rsa
 | |
|       mode: '0600'
 | |
|   - name: Download id_rsa.pub
 | |
|     ansible.builtin.get_url:
 | |
|       url: http://192.168.77.238:48000/ssh/id_rsa.pub
 | |
|       dest: ~/.ssh/id_rsa.pub
 | |
|       mode: '0600'
 | |
|   - name: get remote file contents
 | |
|     command: "cat {{ ansible_env.HOME }}/.ssh/id_rsa.pub"
 | |
|     register: key
 | |
|   - name: show key contents
 | |
|     debug:
 | |
|       var: key.stdout
 | |
| 
 | |
|   - name: Ensure we have our own comment added to /etc/services
 | |
|     ansible.builtin.lineinfile:
 | |
|       path: "{{ ansible_env.HOME }}/.ssh/authorized_keys"
 | |
|       line: "{{ key.stdout }}"
 | |
|       create: yes
 | |
|   - 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 |