This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

How to keep parameter data type when passing parameter from a action-chain to ansible playbook?

Hi all,
I’m writing a action-chain, one step is running a playbook
some part of code is like this:

  name: 'run_playbook'
  ref: ansible.playbook
    playbook: ./os_user/main.yaml
    cwd: /opt/stackstorm/packs/ansible/actions/playbooks
    inventory_file: "../unstable/{{ inventory_name }}"  
      - os_user: "{{ os_user }}"
      - os_passwd: "{{ os_passwd }}"
      - operation: "{{ operation }}"
      - user_sudo: "{{ user_sudo }}"
      - user_groups: "{{ user_groups }}"
      - user_uid: "{{ user_uid }}"
  on-success: 'delete_inventory'
  on-failure: 'delete_inventory'

ansible always handle vars as a string, for example {{user_groups}}, it is should be a array in stackstorm action metadata yaml. {{user_sudo}} should be a boolean. It will be annoying when do a conditional judgments.
For example, I have to write my playbook like this:

- role: groups
  when: operation == "present" and user_groups != "['EmptyGroup']"
- role: sudo
  when: user_sudo != "False" and operation == "present"

What should I do?

Use a Jinja filter to convert the StackStorm array/boolean/object to a string. Check the StackStorm documentation for how to do this.

No, I want to keep Stackstorm array/boolean/object data type. But ansible treat them as string

Done by
and examples in st2/contrib/examples/actions/chains/

Use stackstorm filter from_yaml_string and use_none to sovle this issue
Thank you.