ft(ssh-rotation): Rotate ssh keys
- add task to generate new keys - add task to rotate new keys - add new key to inventory
This commit is contained in:
parent
9570e821e1
commit
06017e09f5
29
.travis.yml
Normal file
29
.travis.yml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
language: python
|
||||||
|
python: "2.7"
|
||||||
|
|
||||||
|
# Use the new container infrastructure
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
# Install ansible
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
packages:
|
||||||
|
- python-pip
|
||||||
|
|
||||||
|
install:
|
||||||
|
# Install ansible
|
||||||
|
- pip install ansible
|
||||||
|
|
||||||
|
# Check ansible version
|
||||||
|
- ansible --version
|
||||||
|
|
||||||
|
# Create ansible.cfg with correct roles_path
|
||||||
|
- printf '[defaults]\nroles_path=../' >ansible.cfg
|
||||||
|
|
||||||
|
script:
|
||||||
|
# Basic role syntax check
|
||||||
|
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
webhooks: https://galaxy.ansible.com/api/v1/notifications/
|
40
README.md
40
README.md
@ -1,2 +1,38 @@
|
|||||||
# ssh-key-rotation
|
Role Name
|
||||||
An ansible role that enables you to rotate ssh keys to your servers
|
=========
|
||||||
|
|
||||||
|
A brief description of the role goes here.
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
------------
|
||||||
|
|
||||||
|
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
|
||||||
|
|
||||||
|
Role Variables
|
||||||
|
--------------
|
||||||
|
|
||||||
|
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
|
||||||
|
|
||||||
|
Dependencies
|
||||||
|
------------
|
||||||
|
|
||||||
|
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
|
||||||
|
|
||||||
|
Example Playbook
|
||||||
|
----------------
|
||||||
|
|
||||||
|
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
|
||||||
|
|
||||||
|
- hosts: servers
|
||||||
|
roles:
|
||||||
|
- { role: username.rolename, x: 42 }
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
BSD
|
||||||
|
|
||||||
|
Author Information
|
||||||
|
------------------
|
||||||
|
|
||||||
|
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
|
||||||
|
6
defaults/main.yml
Normal file
6
defaults/main.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
# defaugalts file for ssh-key-rotation
|
||||||
|
is_exclusive: no
|
||||||
|
should_manage_dir: no
|
||||||
|
authorized_keys_path: '{{ ansible_env.HOME }}/.ssh/authorized_keys'
|
||||||
|
passphrase: 83g!8bfu5M5yy84x
|
22
meta/main.yml
Normal file
22
meta/main.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
galaxy_info:
|
||||||
|
author: Thomas Nyambati
|
||||||
|
description: Ansible role that enables you to rotate ssh keys on your remote servers
|
||||||
|
company: your company (optional)
|
||||||
|
|
||||||
|
# If the issue tracker for your role is not on github, uncomment the
|
||||||
|
# next line and provide a value
|
||||||
|
# issue_tracker_url: http://example.com/issue/tracker
|
||||||
|
|
||||||
|
# Some suggested licenses:
|
||||||
|
# - BSD (default)
|
||||||
|
# - MIT
|
||||||
|
# - GPLv2
|
||||||
|
# - GPLv3
|
||||||
|
# - Apache
|
||||||
|
# - CC-BY
|
||||||
|
license: license (GPLv2, CC-BY, etc)
|
||||||
|
|
||||||
|
min_ansible_version: 2.2
|
||||||
|
galaxy_tags: []
|
||||||
|
dependencies: []
|
||||||
|
|
26
tasks/main.yml
Normal file
26
tasks/main.yml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
# tasks file for ssh-key-rotation
|
||||||
|
- name: Generate New ssh Keys
|
||||||
|
command:
|
||||||
|
ssh-keygen -t rsa
|
||||||
|
-N "{{ passphrase }}" -q
|
||||||
|
-f {{ lookup('env','HOME') + private_key_path }} -y
|
||||||
|
when: inventory_hostname == play_hosts[0]
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
|
- name: Set Authorized key(s) to the authorized keys file
|
||||||
|
become: yes
|
||||||
|
become_user: root
|
||||||
|
authorized_key:
|
||||||
|
exclusive: '{{ is_exclusive }}'
|
||||||
|
user: '{{ host_user }}'
|
||||||
|
state: present
|
||||||
|
path: '{{ authorized_keys_path }}'
|
||||||
|
manage_dir: '{{ should_manage_dir }}'
|
||||||
|
key: "{{ lookup('file', lookup('env','HOME') + public_key_path)}}"
|
||||||
|
|
||||||
|
- debug:
|
||||||
|
msg: "{{ play_hosts }}"
|
||||||
|
|
||||||
|
- name: Test if the new ssh key is allowed to make connections
|
||||||
|
set_fact: ansible_private_ssh_key={{ lookup('file', lookup('env','HOME') + private_key_path)}}
|
1
tests/inventory
Normal file
1
tests/inventory
Normal file
@ -0,0 +1 @@
|
|||||||
|
localhost
|
5
tests/test.yml
Normal file
5
tests/test.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
remote_user: root
|
||||||
|
roles:
|
||||||
|
- ssh-key-rotation
|
2
vars/main.yml
Normal file
2
vars/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# vars file for ssh-key-rotation
|
Loading…
Reference in New Issue
Block a user