Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra_vars option: json format: string "true" turned into boolean "true" #80

Open
mysten-labs-charles-murphy opened this issue Aug 11, 2023 · 4 comments

Comments

@mysten-labs-charles-murphy
Copy link

mysten-labs-charles-murphy commented Aug 11, 2023

I have the following use case:

  - name: Run ansible
    uses: dawidd6/action-ansible-playbook@671974ed60e946e11964cb0c26e69caaa4b1f559
    with:
              directory: ansible/
              playbook: ${{ inputs.playbook }}.yaml
              key: ${{ secrets.SSH_PRIVATE_KEY }}
              requirements: galaxy-requirements.yml
              options: |
                --inventory "inventory/${{ inputs.environment }}.yaml"
                --limit "${{ inputs.limit }}"
                --extra-vars "${{ inputs.extra_vars }}"
                --tags "${{ inputs.tags }}"
                --skip-tags "${{ inputs.skip_tags }}"

if 'extra_vars' is using the json-string method, it can contain a value like so:

{
"attr-a": true
"attr-b": "true"
}

My expectation is that 'attr-a' has the boolean true whilst 'attr-b' has the string 'true'. However, the reality is that both attributes have boolean true.

@dawidd6
Copy link
Owner

dawidd6 commented Aug 11, 2023

Okay, and you are 100% sure it is an issue with the action and not Ansible?

@mysten-labs-charles-murphy
Copy link
Author

@dawidd6 Sorry for the late response.

Here is my ansible playbook CLI:

ansible-playbook [core 2.12.10]
  config file = None
  configured module search path = ['/Users/charles.murphy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /opt/homebrew/lib/python3.11/site-packages/ansible
  ansible collection location = /Users/charles.murphy/.ansible/collections:/usr/share/ansible/collections
  executable location = /opt/homebrew/bin/ansible-playbook
  python version = 3.11.4 (main, Jul 25 2023, 17:36:13) [Clang 14.0.3 (clang-1403.0.22.14.1)]
  jinja version = 3.1.2
  libyaml = True

Here is a playbook:

- name: Show ansible vars
  debug:
    var: vars['{{item}}']
  loop:
    - 'abc'
    - 'string'
    - 'boolean'

Here is my command:

➜  ansible git:(ecr-pull-user-playbook) ✗ ansible-playbook sui/sanity.local.yaml -e '{"abc": "xyz", "string": "true", "boolean": true}'
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Sanity Test (local)] *****************************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************************
ok: [localhost]

TASK [sanity : Show ansible vars] **********************************************************************************************************************************************
ok: [localhost] => (item=abc) => {
    "ansible_loop_var": "item",
    "item": "abc",
    "vars['abc']": "xyz"
}
ok: [localhost] => (item=string) => {
    "ansible_loop_var": "item",
    "item": "string",
    "vars['string']": "true"
}
ok: [localhost] => (item=boolean) => {
    "ansible_loop_var": "item",
    "item": "boolean",
    "vars['boolean']": true
}

TASK [Run tree command on selected directories] ********************************************************************************************************************************
skipping: [localhost]

PLAY RECAP *********************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

This works as expected on the command line.

@dawidd6
Copy link
Owner

dawidd6 commented Aug 16, 2023

Don't know if that makes any difference, but in the action input you are surrounding your extra vars with double quotes and in the cli it is single quotes. Try using the same quotes here and there.

@mysten-labs-charles-murphy
Copy link
Author

ok, thanks. i will try it next time i run into the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants