ansible-st2 icon indicating copy to clipboard operation
ansible-st2 copied to clipboard

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

Open arm4b opened this issue 8 years ago • 1 comments

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):

  • https://www.ansible.com/blog/how-to-extend-ansible-through-plugins
  • http://docs.ansible.com/ansible/playbooks_lookups.html

arm4b avatar Jan 31 '17 18:01 arm4b

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

johnarnold avatar Jul 26 '17 02:07 johnarnold