StackStorm / ansible-st2

Ansible Roles and Playbooks to deploy StackStorm
https://galaxy.ansible.com/StackStorm/stackstorm/
Apache License 2.0
100 stars 75 forks source link

Add functionality to get/set K/V pairs in st2 datastore #108

Open arm4b opened 7 years ago

arm4b commented 7 years ago

Similar to Pack Install #74 we'll need an abstraction for st2 key/value store.

For example define a list of K/V pairs in yaml which will be added in st2 datastore during Ansible provisioning.

See: https://docs.stackstorm.com/datastore.html

At a low level it could be implemented via Ansible plugins/modules (lookup/set):

johnarnold commented 7 years ago

Current workaround:

---
- name: set path vars for datastore keys
  set_fact:
    st2_keys_path: /etc/st2/st2_keys.json
    st2_keys_imported_path: /etc/st2/st2_keys.touch

- name: load datastore vars from file
  include_vars:
    file: st2_keys.yml

- name: Check if keys imported file exists
  stat:
    path: "{{st2_keys_imported_path}}"
  register: keys_exist
  become: true

- name: Write key file
  copy:
    content: "{{st2_keys | to_json}}"
    dest: "{{st2_keys_path}}"
  when: keys_exist.stat.exists == False
  become: true

- name: Import Keys
  become: true
  shell: "st2 key load {{st2_keys_path}} && rm -f {{st2_keys_path}} && touch {{st2_keys_imported_path}}"
  args:
    creates: "{{st2_keys_imported_path}}"
  when: keys_exist.stat.exists == False