Skip to content

Instantly share code, notes, and snippets.

@lostsnow
Last active October 4, 2020 08:39
Show Gist options
  • Save lostsnow/a3822b6358721dfb2538d4d9841b97dd to your computer and use it in GitHub Desktop.
Save lostsnow/a3822b6358721dfb2538d4d9841b97dd to your computer and use it in GitHub Desktop.
Ansible authorized_key playbook
---
- name: authorized_key
hosts: node_exporters
tasks:
- name: set ubuntu user name
set_fact: sys_user=ubuntu
when: ansible_distribution == 'Ubuntu'
- name: set centos user name
set_fact: sys_user=centos
when: ansible_distribution == 'CentOS'
- name: SYSTEM - Set authorized key took from file
tags: jenkins
authorized_key:
user: "{{ sys_user }}"
state: present
key: "{{ lookup('file', '/path/to/ssh_rsa.pub') }}"
- name: SYSTEM - Remove authorized key took from file
tags: jenkins
authorized_key:
user: "{{ sys_user }}"
state: absent
key: "{{ lookup('file', '/path/to/ssh_rsa.remove.pub') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment