Skip to content

Commit

Permalink
Merge pull request #17 from idealista/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
adrian-arapiles authored Mar 4, 2022
2 parents 6d12e50 + df338f5 commit 6cd1878
Show file tree
Hide file tree
Showing 9 changed files with 357 additions and 371 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
dist: xenial
language: python
python: "3.7"
python: "3.9"
os: linux
services:
- docker
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ This project adheres to [Semantic Versioning](http://semver.org/) and [Keep a ch

[Full Changelog](https://github.com/idealista/consul_keystore_role/compare/master...develop)

## [2.0.1] 2022-03-04
### Fixed
- *[#13](https://github.com/idealista/consul_keystore_role/issues/13) Fixed delete steps making diff of whole keys and files processed. @adrian-arapiles*

## [2.0.0] 2022-02-03

### Added
Expand Down
14 changes: 7 additions & 7 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ verify_ssl = true
name = "pypi"

[packages]
ansible = "==2.10.7"
molecule = "==3.1.5"
molecule-docker = "==0.2.4"
docker = "==4.4.4"
ansible-lint = "==5.1.2"
yamllint = "==1.26.2"
ansible = "==5.3.0"
molecule = "==3.6.1"
molecule-docker = "==1.1.0"
docker = "==5.0.3"
ansible-lint = "==5.4.0"
yamllint = "==1.26.3"

[dev-packages]

[requires]
python_version = "3.7"
python_version = "3.9"
620 changes: 290 additions & 330 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion molecule/default/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ FROM {{ item.image }}

# install minimal packages for debian slim images
RUN apt-get update && \
apt-get install -y python sudo bash ca-certificates iproute2 systemd systemd-sysv python-pip && \
apt-get install -y python python3 sudo bash ca-certificates iproute2 systemd systemd-sysv python-pip python3-pip && \
apt-get clean
3 changes: 3 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,8 @@ platforms:

provisioner:
name: ansible
env:
PY_COLORS: 1
ANSIBLE_FORCE_COLOR: 1
verifier:
name: ansible
20 changes: 20 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
---

- name: Consul | Set fact consul_backup_properties
set_fact:
consul_backup_all_properties: []
consul_set_properties: []

- name: Consul | Keys yml files
include_tasks: "manage_keys_{{ (file.name | basename).split('.') | last }}_file.yml"
run_once: true
Expand All @@ -14,3 +19,18 @@
tags:
- consul_keystore_configure
when: consul_keystore_name is defined

- name: Consul | Delete diff keys
consul_kv:
host: "{{ consul_keystore_server }}"
port: "{{ consul_keystore_http_port }}"
token: "{{ consul_keystore_acl_token }}"
key: "{{ key }}"
state: absent
loop: "{{ consul_backup_all_properties | difference(consul_set_properties) }}"
loop_control:
loop_var: key
when:
- consul_backup_all_properties | length > 0
- consul_set_properties is defined
- consul_set_properties | length > 0
51 changes: 25 additions & 26 deletions tasks/manage_keys_yml_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
set_fact:
consul_to_upload_properties: "{{ consul_yaml_file | flatten_collection(sep=consul_key_separator) }}"

- name: Update consul_setted_properties
set_fact:
consul_set_properties: "{{ consul_set_properties + ([consul_key_parent + '/'] | product(consul_to_upload_properties.keys()) | map('join')) | list }}"

- name: Consul | Read {{ consul_key_parent }} properties
consul_kv:
host: "{{ consul_keystore_server }}"
Expand All @@ -38,16 +42,16 @@

- name: Set consul_backup_keys
set_fact:
consul_backup_keys: "{{ consul_backup_properties.data | map(attribute='Key') | map('regex_replace', consul_key_parent + '/') | list | filter | list }}"
consul_backup_keys: "{{ consul_backup_properties.data | map(attribute='Key') | list | filter | list }}"

- name: Update consul_backup_keys expanded
set_fact:
consul_backup_keys: "{{ consul_backup_keys | map('regex_replace', '\\.', '/') | list }}"
when: consul_keystore_expand_keys

- name: Set consul_remove_keys
- name: Update consul_backup_all_keys
set_fact:
consul_remove_keys: "{{ consul_backup_keys | difference(consul_to_upload_properties.keys()) }}"
consul_backup_all_properties: "{{ consul_backup_all_properties + consul_backup_keys }}"

- name: Consul | Upload / Update {{ consul_key_parent }} properties
consul_kv:
Expand All @@ -59,29 +63,22 @@
with_dict: "{{ consul_to_upload_properties }}"
loop_control:
loop_var: property

- name: Consul | Delete old {{ consul_key_parent }} properties
consul_kv:
host: "{{ consul_keystore_server }}"
port: "{{ consul_keystore_http_port }}"
token: "{{ consul_keystore_acl_token }}"
key: "{{ consul_key_parent + '/' + key }}"
state: absent
with_items: "{{ consul_remove_keys }}"
loop_control:
loop_var: key
when: consul_check_yaml_file.stat.exists and consul_keystore_properties_file_format == 'kv'

- name: Consul | Manage keys from {{ consul_keystore_properties_path }}/{{ consul_keystore_properties_file }} file
block:
- name: Set consul_key_separator
- name: Set consul_to_upload_properties
set_fact:
consul_to_upload_properties: "{{ lookup('file', consul_keystore_properties_path + '/' + consul_keystore_properties_file) }}"

- name: Set consul_key_parent
set_fact:
consul_key_parent: "{{ consul_keystore_mountpoint + '/' + consul_keystore_name + '/' + consul_keystore_properties_file_name }}"

- name: Update consul_backup_all_keys
set_fact:
consul_set_properties: "{{ consul_set_properties + [consul_key_parent + '/' + consul_keystore_properties_key] }}"

- name: Consul | Read {{ consul_key_parent }} properties
consul_kv:
host: "{{ consul_keystore_server }}"
Expand All @@ -92,22 +89,24 @@
state: present
register: consul_backup_properties

- name: Set consul_backup_keys
set_fact:
consul_backup_keys: "{{ consul_backup_properties.data | map(attribute='Key') | list | filter | list }}"

- name: Update consul_backup_keys expanded
set_fact:
consul_backup_keys: "{{ consul_backup_keys | map('regex_replace', '\\.', '/') | list }}"
when: consul_keystore_expand_keys

- name: Update consul_backup_all_keys
set_fact:
consul_backup_all_properties: "{{ consul_backup_all_properties + consul_backup_keys }}"

- name: Consul | Upload / Update {{ consul_key_parent }} properties
consul_kv:
host: "{{ consul_keystore_server }}"
port: "{{ consul_keystore_http_port }}"
token: "{{ consul_keystore_acl_token }}"
key: "{{ consul_key_parent + '/' + consul_keystore_properties_key }}"
value: "{{ consul_to_upload_properties }}"

- name: Consul | Delete old {{ consul_key_parent }} properties
consul_kv:
host: "{{ consul_keystore_server }}"
port: "{{ consul_keystore_http_port }}"
token: "{{ consul_keystore_acl_token }}"
key: "{{ consul_key_parent + '/' + key }}"
state: absent
with_items: "{{ consul_remove_keys }}"
loop_control:
loop_var: key
when: consul_check_yaml_file.stat.exists and consul_keystore_properties_file_format == 'file'
12 changes: 6 additions & 6 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ansible==2.10.7
molecule==3.1.5
molecule-docker==0.2.4
docker==4.4.4
ansible-lint==5.1.2
yamllint==1.26.2
ansible==5.3.0
molecule==3.6.1
molecule-docker==1.1.0
docker==5.0.3
ansible-lint==5.4.0
yamllint==1.26.3

0 comments on commit 6cd1878

Please sign in to comment.