forked from openstack/kayobe-config
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from jovial/redact
Add custom ansible playbook to dump overcloud configuration
- Loading branch information
Showing
6 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
|
||
- name: dump config | ||
hosts: localhost | ||
roles: | ||
- name: kayobe-config-dump |
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
8 changes: 8 additions & 0 deletions
8
etc/kayobe/ansible/roles/kayobe-config-dump/defaults/main.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
config_dump_path: /tmp/kayobe-config-dump | ||
output_dir: "{{ lookup('env', 'PWD') ~ '/redacted-config' }}" | ||
# You can't use ANSIBLE_VAULT_PASSWORD_FILE as you will get: | ||
# ERROR! The vault-ids default,default are available to encrypt. | ||
# Specify the vault-id to encrypt with --encrypt-vault-id | ||
vault_password_file: ~/vaultpassword | ||
dummy_password: password | ||
user: stack |
34 changes: 34 additions & 0 deletions
34
etc/kayobe/ansible/roles/kayobe-config-dump/filter_plugins/filters.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import yaml | ||
|
||
class FilterModule(object): | ||
def filters(self): | ||
return { | ||
'redact': self.redact, | ||
} | ||
|
||
def redact(self, input): | ||
data = yaml.load(input) | ||
return "---\n" + yaml.dump(redact(data), default_flow_style=False) | ||
|
||
def redact_int(_): | ||
return 1234 | ||
|
||
def redact_float(_): | ||
return 1.234 | ||
|
||
def redact_str(_): | ||
return "redacted" | ||
|
||
def redact_list(xs): | ||
return [redact(x) for x in xs] | ||
|
||
def redact_dict(x): | ||
# keys are assumed to not be secret | ||
return {key:redact(value) for key,value in x.items()} | ||
|
||
def redact_NoneType(x): | ||
return | ||
|
||
def redact(x): | ||
type_ = type(x).__name__ | ||
return globals()["redact_%s" % type_](x) |
65 changes: 65 additions & 0 deletions
65
etc/kayobe/ansible/roles/kayobe-config-dump/tasks/main.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
|
||
- name: create temporary directory | ||
tempfile: | ||
state: directory | ||
suffix: kayobe_config | ||
register: tempfile_output | ||
- block: | ||
- name: make a copy of the config | ||
synchronize: | ||
src: "{{ original_config_path }}" | ||
dest: "{{ path }}" | ||
recursive: yes | ||
delegate_to: "{{ inventory_hostname }}" | ||
- name: make a temp vault password file | ||
copy: | ||
content: "{{ dummy_password }}" | ||
dest: "{{ temp_vault_password_file }}" | ||
- include_tasks: 'redact.yml' | ||
vars: | ||
redact_path: "{{ item }}" | ||
with_items: | ||
- "{{ password_yml_path }}" | ||
- "{{ secrets_yml_path }}" | ||
- name: generate config | ||
command: >- | ||
kayobe overcloud service configuration generate | ||
--node-config-dir "{{ config_dump_path }}" | ||
--extra-vars "ansible_user={{ user }}" | ||
--kolla-extra-vars "ansible_user={{ user }}" | ||
environment: "{{ env }}" | ||
register: result | ||
- file: | ||
path: "{{ output_dir }}" | ||
state: directory | ||
- name: save kayobe config | ||
command: >- | ||
kayobe overcloud service configuration save | ||
--node-config-dir "{{ config_dump_path }}" | ||
--output-dir "{{ output_dir }}" | ||
--extra-vars "ansible_user={{ user }}" | ||
environment: "{{ env }}" | ||
register: result | ||
vars: | ||
original_config_path: "{{ lookup('env', 'KAYOBE_CONFIG_PATH') ~ '/../..' }}" | ||
temp_vault_password_file: "{{ path ~ '/vault.pass' }}" | ||
path: "{{ tempfile_output.path }}" | ||
password_yml_path: "{{ path ~ '/etc/kayobe/kolla/passwords.yml' }}" | ||
secrets_yml_path: "{{ path ~ '/etc/kayobe/secrets.yml' }}" | ||
env: | ||
KAYOBE_CONFIG_PATH: "{{ path ~ '/etc/kayobe' }}" | ||
KAYOBE_VAULT_PASSWORD: "{{ dummy_password }}" | ||
KAYOBE_BASE_PATH: "{{ path }}" | ||
rescue: | ||
- copy: | ||
content: "{{ result.stdout }}" | ||
dest: /tmp/kayobe-config-dump-debug | ||
when: result | default(False) and result.rc != 0 | ||
always: | ||
- debug: | ||
var: tempfile_output | ||
- name: remove tempdir | ||
file: | ||
path: "{{ tempfile_output.path }}" | ||
state: absent |
13 changes: 13 additions & 0 deletions
13
etc/kayobe/ansible/roles/kayobe-config-dump/tasks/redact.yml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
|
||
- name: redact passwords | ||
copy: | ||
content: "{{ plaintext | redact }}" | ||
dest: "{{ redact_path }}" | ||
mode: 0600 | ||
vars: | ||
plaintext: "{{ lookup('pipe', 'ansible-vault view --vault-id {{ vault_password_file }} ' + redact_path) }}" | ||
|
||
- name: reencrypt | ||
command: >- | ||
ansible-vault encrypt --vault-id "{{ temp_vault_password_file }}" --encrypt-vault-id default "{{ redact_path }}" |