Adjust SSH key creation method for repo servers
This patch ensures that the authorized_keys ansible module, as well as the built in "generate_ssh_keys" flag for user creation, so that we can avoid using shell out commands. Additionally, this moves the key synchronisation to use ansible variables instead of the memcache server. Change-Id: I4fe7620cae6bf68f4c0fe248cb1dfa3c24e44110 Closes-Bug: #1477494
This commit is contained in:
parent
c19915251f
commit
c924a7652f
@ -31,6 +31,10 @@ repo_auto_rebuild: false
|
|||||||
|
|
||||||
repo_memcached_servers: "{% for host in groups['repo_all'] %}{{ hostvars[host]['ansible_ssh_host'] }}:{{ memcached_port }}{% if not loop.last %},{% endif %}{% endfor %}"
|
repo_memcached_servers: "{% for host in groups['repo_all'] %}{{ hostvars[host]['ansible_ssh_host'] }}:{{ memcached_port }}{% if not loop.last %},{% endif %}{% endfor %}"
|
||||||
|
|
||||||
|
# If you want to regenerate the repo users SSH keys, on each run, set this var to True
|
||||||
|
# Otherwise keys will be generated on the first run and not regenerated each run.
|
||||||
|
repo_recreate_keys: False
|
||||||
|
|
||||||
repo_apt_packages:
|
repo_apt_packages:
|
||||||
- aptitude
|
- aptitude
|
||||||
- bridge-utils
|
- bridge-utils
|
||||||
|
@ -17,16 +17,10 @@
|
|||||||
- include: repo_install.yml
|
- include: repo_install.yml
|
||||||
- include: repo_post_install.yml
|
- include: repo_post_install.yml
|
||||||
|
|
||||||
- include: repo_key_create.yml
|
- include: repo_key_populate.yml
|
||||||
|
|
||||||
- include: repo_key_store.yml
|
|
||||||
when: >
|
|
||||||
inventory_hostname == groups['pkg_repo'][0] and
|
|
||||||
groups.repo_all|length > 1
|
|
||||||
|
|
||||||
- include: repo_key_distribute.yml
|
- include: repo_key_distribute.yml
|
||||||
when: >
|
when: >
|
||||||
inventory_hostname != groups['pkg_repo'][0] and
|
|
||||||
groups.repo_all|length > 1
|
groups.repo_all|length > 1
|
||||||
|
|
||||||
- include: repo_sync_manager.yml
|
- include: repo_sync_manager.yml
|
||||||
|
@ -1,54 +0,0 @@
|
|||||||
---
|
|
||||||
# Copyright 2014, Rackspace US, Inc.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
- name: Remove old key file(s) if found
|
|
||||||
file:
|
|
||||||
path: "{{ item }}"
|
|
||||||
state: "absent"
|
|
||||||
with_items:
|
|
||||||
- "{{ repo_service_home_folder }}/.ssh/authorized_keys"
|
|
||||||
- "{{ repo_service_home_folder }}/.ssh/id_rsa"
|
|
||||||
- "{{ repo_service_home_folder }}/.ssh/id_rsa.pub"
|
|
||||||
|
|
||||||
- name: Create the nginx SSH key if it doesnt exist
|
|
||||||
shell: |
|
|
||||||
su - nginx -c 'ssh-keygen -f {{ repo_service_home_folder }}/.ssh/id_rsa -t rsa -q -N ""'
|
|
||||||
|
|
||||||
- name: Create empty 'authorized_keys' file
|
|
||||||
file:
|
|
||||||
path: "{{ repo_service_home_folder }}/.ssh/authorized_keys"
|
|
||||||
state: "touch"
|
|
||||||
|
|
||||||
- name: Change permissions on the generated keys
|
|
||||||
file:
|
|
||||||
path: "{{ item.path }}"
|
|
||||||
group: "www-data"
|
|
||||||
owner: "nginx"
|
|
||||||
mode: "{{ item.mode }}"
|
|
||||||
with_items:
|
|
||||||
- { path: "{{ repo_service_home_folder }}/.ssh/authorized_keys", mode: "0700" }
|
|
||||||
- { path: "{{ repo_service_home_folder }}/.ssh/id_rsa", mode: "0600" }
|
|
||||||
- { path: "{{ repo_service_home_folder }}/.ssh/id_rsa.pub", mode: "0644" }
|
|
||||||
|
|
||||||
- name: Get public key contents
|
|
||||||
command: |
|
|
||||||
cat {{ repo_service_home_folder }}/.ssh/id_rsa.pub
|
|
||||||
register: nginx_pub
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: Build authorized keys
|
|
||||||
shell: |
|
|
||||||
echo "{{ nginx_pub.stdout }}" | tee -a {{ repo_service_home_folder }}/.ssh/authorized_keys
|
|
||||||
delegate_to: "{{ groups['pkg_repo'][0] }}"
|
|
@ -13,21 +13,11 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
- name: Retrieve authorized keys
|
- name: Create authorized keys file from host vars
|
||||||
memcached:
|
authorized_key:
|
||||||
name: "{{ item.name }}"
|
user: "{{ repo_service_user_name }}"
|
||||||
file_path: "{{ item.src }}"
|
key: "{{ hostvars[item]['repo_pubkey'] }}"
|
||||||
state: "retrieve"
|
with_items: groups['pkg_repo']
|
||||||
file_mode: "{{ item.file_mode }}"
|
|
||||||
dir_mode: "{{ item.dir_mode }}"
|
|
||||||
server: "{{ repo_memcached_servers }}"
|
|
||||||
encrypt_string: "{{ memcached_encryption_key }}"
|
|
||||||
with_items:
|
|
||||||
- { src: "{{ repo_service_home_folder }}/.ssh/authorized_keys", name: "authorized_keys", file_mode: "0640", dir_mode: "0750" }
|
|
||||||
register: memcache_keys
|
|
||||||
until: memcache_keys|success
|
|
||||||
retries: 5
|
|
||||||
delay: 2
|
|
||||||
tags:
|
tags:
|
||||||
- repo-key
|
- repo-key
|
||||||
- repo-key-store
|
- repo-key-store
|
||||||
|
@ -13,19 +13,18 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
- name: Distribute authorized keys for cluster consumption
|
- name: Get public key contents and store as var
|
||||||
memcached:
|
command: |
|
||||||
name: "{{ item.name }}"
|
cat {{ repo_service_home_folder }}/.ssh/id_rsa.pub
|
||||||
file_path: "{{ item.src }}"
|
register: repo_pub
|
||||||
state: "present"
|
changed_when: false
|
||||||
server: "{{ repo_memcached_servers }}"
|
|
||||||
encrypt_string: "{{ memcached_encryption_key }}"
|
|
||||||
with_items:
|
|
||||||
- { src: "{{ repo_service_home_folder }}/.ssh/authorized_keys", name: "authorized_keys" }
|
|
||||||
register: memcache_keys
|
|
||||||
until: memcache_keys|success
|
|
||||||
retries: 5
|
|
||||||
delay: 2
|
|
||||||
tags:
|
tags:
|
||||||
- repo-key
|
- repo-key
|
||||||
- repo-key-distribute
|
- repo-key-create
|
||||||
|
|
||||||
|
- name: Register a fact for the repo user pub key
|
||||||
|
set_fact:
|
||||||
|
repo_pubkey: "{{ repo_pub.stdout }}"
|
||||||
|
tags:
|
||||||
|
- repo-key
|
||||||
|
- repo-key-create
|
@ -21,7 +21,20 @@
|
|||||||
tags:
|
tags:
|
||||||
- pkg-repo-group
|
- pkg-repo-group
|
||||||
|
|
||||||
- name: Create the nova system user
|
- name: Remove old key file(s) if found
|
||||||
|
file:
|
||||||
|
path: "{{ item }}"
|
||||||
|
state: "absent"
|
||||||
|
with_items:
|
||||||
|
- "{{ repo_service_home_folder }}/.ssh/authorized_keys"
|
||||||
|
- "{{ repo_service_home_folder }}/.ssh/id_rsa"
|
||||||
|
- "{{ repo_service_home_folder }}/.ssh/id_rsa.pub"
|
||||||
|
when: repo_recreate_keys | bool
|
||||||
|
tags:
|
||||||
|
- repo-key
|
||||||
|
- repo-key-create
|
||||||
|
|
||||||
|
- name: Create the nginx system user
|
||||||
user:
|
user:
|
||||||
name: "{{ repo_service_user_name }}"
|
name: "{{ repo_service_user_name }}"
|
||||||
group: "{{ repo_service_group_name }}"
|
group: "{{ repo_service_group_name }}"
|
||||||
@ -30,8 +43,11 @@
|
|||||||
system: "yes"
|
system: "yes"
|
||||||
createhome: "yes"
|
createhome: "yes"
|
||||||
home: "{{ repo_service_home_folder }}"
|
home: "{{ repo_service_home_folder }}"
|
||||||
|
generate_ssh_key: "yes"
|
||||||
tags:
|
tags:
|
||||||
- pkg-repo-user
|
- pkg-repo-user
|
||||||
|
- repo-key
|
||||||
|
- repo-key-create
|
||||||
|
|
||||||
- name: File and directory setup
|
- name: File and directory setup
|
||||||
file:
|
file:
|
||||||
|
Loading…
Reference in New Issue
Block a user