Skip to content

Instantly share code, notes, and snippets.

@cloudnull
Created April 8, 2016 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudnull/15ff608e027b07d12fdbd256aeadf860 to your computer and use it in GitHub Desktop.
Save cloudnull/15ff608e027b07d12fdbd256aeadf860 to your computer and use it in GitHub Desktop.
Re key all containers using a specific public key within an OpenStack Ansible environment. USAGE: openstack-ansible /tmp/rekey.yml -e "user_provided_key=~/.ssh/id_rsa.pub"
---
- name: Re-Key authorized keys in containers
hosts: localhost
connection: local
user: root
tasks:
- name: Store user user provided key
command: "cat {{ user_provided_key }}"
register: _stored_user_provided_key
- name: load containers as facts
set_fact:
stored_user_provided_key: "{{ _stored_user_provided_key.stdout }}"
- name: Re-Key authorized keys in containers
hosts: hosts
user: root
tasks:
- debug: var=hostvars["localhost"]["stored_user_provided_key"]
- name: Discover containers
command: lxc-ls
register: _discovered_containers
- name: load containers as facts
set_fact:
discovered_containers: "{{ _discovered_containers.stdout.split() }}"
- name: Inject new key
lxc_container:
name: "{{ item }}"
container_command: |
echo '{{ hostvars["localhost"]["stored_user_provided_key"] }}' | tee /root/.ssh/authorized_keys
with_items: discovered_containers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment