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

Boolean extra variables being interpreted as Strings

Open Pexers opened this issue 1 year ago • 2 comments

Jenkins and plugins versions report

Environment
Jenkins: 2.413
OS: Linux - 5.15.0-76-generic
Java: 11.0.19 - Ubuntu (OpenJDK 64-Bit Server VM)
---
ansible:240.vc26740a_625c0

The only way Ansible can detect boolean extra-variables is by passing JSON using the extras parameter, like shown below.
Otherwise, they are interpreted as Strings.

ansiblePlaybook(
    playbook: './src/main.yml',
    extras: '''
        --extra-vars "{bar: false}"
    '''
)

Equivalent when using the terminal:

$ ansible-playbook playbook.yml --extra-vars "{bar: false}"

What Operating System are you using (both controller, and any agents involved in the problem)?

Alpine Docker container running Ansible.

Reproduction steps

  1. Declare a variable in Ansible that should default to a different value if extra variable is given as false:
foo: "{{ bar | default(99, true) }}"
  1. Run the script through Jenkins:
ansiblePlaybook(
    playbook: './src/main.yml',
    extraVars: [
        'bar': false
    ]
)

Expected Results

foo: 99

Actual Results

foo: "false"

Pexers avatar Jul 17 '23 13:07 Pexers

I don't think passing JSON --extra-vars was ever supported on the plugin. Feel free to submit a PR

jonesbusy avatar Jul 30 '23 08:07 jonesbusy

I've edited the issue to make it more clear. If I find some free time I will be submitting a PR, thank you. 🙂

Pexers avatar Jul 30 '23 12:07 Pexers

@Pexers Any plan on adding this enhancement to Jenkin's ansible plugin?

mehulgogri avatar Jun 14 '24 20:06 mehulgogri

@mehulgogri I will give it a shot for sure, thanks for the reminder!

Pexers avatar Jun 14 '24 21:06 Pexers