Created
July 27, 2015 02:30
-
-
Save hongqn/62d528116eb5a4a9e4b7 to your computer and use it in GitHub Desktop.
Ansible playbook to distribute ssh public key to hosts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: all | |
gather_facts: no | |
tasks: | |
- local_action: command grep '{{ ansible_ssh_host }} ' /root/.ssh/known_hosts | |
register: exists | |
ignore_errors: True | |
changed_when: False | |
- local_action: shell ssh-keyscan -p {{ ansible_ssh_port|default(22) }} {{ ansible_ssh_host }} | |
register: result | |
when: exists|failed | |
- local_action: known_hosts path='/root/.ssh/known_hosts' host={{ ansible_ssh_host }} key="{{ result.stdout }}" | |
when: exists|failed | |
- hosts: dmz-vms | |
tasks: | |
- yum: pkg=libselinux-python | |
- hosts: all | |
tasks: | |
- authorized_key: user=root key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment