{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/17193","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/17193/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/17193/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/17193/events","html_url":"https://github.com/ansible/ansible/issues/17193","id":172667963,"number":17193,"title":"Unable to pass boolean value False through --extra-vars argument","user":{"login":"ksmets","id":2758297,"avatar_url":"https://avatars3.githubusercontent.com/u/2758297?v=3","gravatar_id":"","url":"https://api.github.com/users/ksmets","html_url":"https://github.com/ksmets","followers_url":"https://api.github.com/users/ksmets/followers","following_url":"https://api.github.com/users/ksmets/following{/other_user}","gists_url":"https://api.github.com/users/ksmets/gists{/gist_id}","starred_url":"https://api.github.com/users/ksmets/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ksmets/subscriptions","organizations_url":"https://api.github.com/users/ksmets/orgs","repos_url":"https://api.github.com/users/ksmets/repos","events_url":"https://api.github.com/users/ksmets/events{/privacy}","received_events_url":"https://api.github.com/users/ksmets/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-23T10:47:43Z","updated_at":"2017-06-02T10:29:05Z","closed_at":"2016-08-24T07:04:31Z","body":"<!---\nPlease do not report issues/requests related to Ansible modules here !!\n\nReport them to the appropriate modules-core or modules-extras project:\n  - https://github.com/ansible/ansible-modules-core/issues\n  - https://github.com/ansible/ansible-modules-extras/issues\n\nAlso verify first that your issue/request is not already reported in GitHub\n-->\n##### ISSUE TYPE\n\n<!--- Pick one below and delete the rest: -->\n- Bug Report\n##### COMPONENT NAME\n\n<!--- Name of the plugin/task/feature -->\n\nextra-vars\nwhen\n##### ANSIBLE VERSION\n\n<!--- Paste verbatim output from “ansible --version” between quotes below -->\n\n```\nansible 2.1.1.0\n```\n##### CONFIGURATION\n\n<!---\nMention any settings you have changed/added/removed in ansible.cfg\n(or using the ANSIBLE_* environment variables).\n-->\n##### OS / ENVIRONMENT\n\n<!---\nMention the OS you are running Ansible from, and the OS you are\nmanaging, or say “N/A” for anything that is not platform-specific.\n-->\n\n```\nDarwin alfheim.local 15.5.0 Darwin Kernel Version 15.5.0: Tue Apr 19 18:36:36 PDT 2016; root:xnu-3248.50.21~8/RELEASE_X86_64 x86_64\n```\n##### SUMMARY\n\n<!--- Explain the problem briefly -->\n\nUnable to pass boolean variable False via `--extra-vars` arguments\n##### STEPS TO REPRODUCE\n\n<!---\nFor bugs, show exactly how to reproduce the problem.\nFor new features, show how the feature would be used.\n-->\n\n<!--- Paste example playbooks or commands between quotes below -->\n\n```\ncat test.yml\n```\n\n```\n- hosts: localhost\n  vars:\n  - foobar: True\n  tasks:\n  - debug: var=foobar\n\n  - debug: var=foobar\n    when: not foobar\n\n  - debug: var=foobar\n    when: foobar\n\n- hosts: localhost\n  vars:\n  - foobar: False\n  tasks:\n  - debug: var=foobar\n\n  - debug: var=foobar\n    when: not foobar\n\n  - debug: var=foobar\n    when: foobar\n```\n\n<!--- You can also paste gist.github.com links for larger files -->\n##### EXPECTED RESULTS\n\n<!--- What did you expect to happen when running the steps above? -->\n\nRunning playbook without passing extra-vars to override foobar variable works as expected.\n\n```\nansible-playbook -i inventory test.yml\n```\n\n```\nPLAY [localhost] ***************************************************************\n\nTASK [setup] *******************************************************************\nok: [localhost]\n\nTASK [debug] *******************************************************************\nok: [localhost] => {\n    \"foobar\": true\n}\n\nTASK [debug] *******************************************************************\nskipping: [localhost]\n\nTASK [debug] *******************************************************************\nok: [localhost] => {\n    \"foobar\": true\n}\n\nPLAY [localhost] ***************************************************************\n\nTASK [setup] *******************************************************************\nok: [localhost]\n\nTASK [debug] *******************************************************************\nok: [localhost] => {\n    \"foobar\": false\n}\n\nTASK [debug] *******************************************************************\nok: [localhost] => {\n    \"foobar\": false\n}\n\nTASK [debug] *******************************************************************\nskipping: [localhost]\n\nPLAY RECAP *********************************************************************\nlocalhost                  : ok=6    changed=0    unreachable=0    failed=0\n```\n\nRunning playbook with passing foobar=True as extra-vars parameter works as expected.\n\n```\nansible-playbook -i inventory test.yml -e foobar=True\n```\n\n```\nPLAY [localhost] ***************************************************************\n\nTASK [setup] *******************************************************************\nok: [localhost]\n\nTASK [debug] *******************************************************************\nok: [localhost] => {\n    \"foobar\": true\n}\n\nTASK [debug] *******************************************************************\nskipping: [localhost]\n\nTASK [debug] *******************************************************************\nok: [localhost] => {\n    \"foobar\": true\n}\n\nPLAY [localhost] ***************************************************************\n\nTASK [setup] *******************************************************************\nok: [localhost]\n\nTASK [debug] *******************************************************************\nok: [localhost] => {\n    \"foobar\": true\n}\n\nTASK [debug] *******************************************************************\nskipping: [localhost]\n\nTASK [debug] *******************************************************************\nok: [localhost] => {\n    \"foobar\": true\n}\n\nPLAY RECAP *********************************************************************\nlocalhost                  : ok=6    changed=0    unreachable=0    failed=0\n```\n##### ACTUAL RESULTS\n\n<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->\n\n<!--- Paste verbatim command output between quotes below -->\n\nRunning playbook with passing foobar=False as extra-vars parameter does _not_ work as expected. Both `when: foobar` as `when: not foobar` are skipped. Only `when: foobar` should be skipped.\n\n```\nansible-playbook -i inventory test.yml -e foobar=False\n```\n\n```\nPLAY [localhost] ***************************************************************\n\nTASK [setup] *******************************************************************\nok: [localhost]\n\nTASK [debug] *******************************************************************\nok: [localhost] => {\n    \"foobar\": false\n}\n\nTASK [debug] *******************************************************************\nskipping: [localhost]\n\nTASK [debug] *******************************************************************\nskipping: [localhost]\n\nPLAY [localhost] ***************************************************************\n\nTASK [setup] *******************************************************************\nok: [localhost]\n\nTASK [debug] *******************************************************************\nok: [localhost] => {\n    \"foobar\": false\n}\n\nTASK [debug] *******************************************************************\nskipping: [localhost]\n\nTASK [debug] *******************************************************************\nskipping: [localhost]\n\nPLAY RECAP *********************************************************************\n```\n\nNote that the variable is interpreted as boolean as it displays `'foobar: false'`, while if I would pass `-e foobar=false\"` it would show `'foobar: \"false\"'` as it then gets interpreted as string. The only way I could get the example to work is when I change `when: not foobar` to `when: not foobar|bool`, but this isn't mentioned in the documentation at http://docs.ansible.com/ansible/playbooks_conditionals.html#the-when-statement (see use of boolean variable epic).\n\nAny ideas how to resolve this issue?\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/305750420","html_url":"https://github.com/ansible/ansible/issues/17193#issuecomment-305750420","issue_url":"https://api.github.com/repos/ansible/ansible/issues/17193","id":305750420,"user":{"login":"Sabbasth","id":5691241,"avatar_url":"https://avatars3.githubusercontent.com/u/5691241?v=3","gravatar_id":"","url":"https://api.github.com/users/Sabbasth","html_url":"https://github.com/Sabbasth","followers_url":"https://api.github.com/users/Sabbasth/followers","following_url":"https://api.github.com/users/Sabbasth/following{/other_user}","gists_url":"https://api.github.com/users/Sabbasth/gists{/gist_id}","starred_url":"https://api.github.com/users/Sabbasth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Sabbasth/subscriptions","organizations_url":"https://api.github.com/users/Sabbasth/orgs","repos_url":"https://api.github.com/users/Sabbasth/repos","events_url":"https://api.github.com/users/Sabbasth/events{/privacy}","received_events_url":"https://api.github.com/users/Sabbasth/received_events","type":"User","site_admin":false},"created_at":"2017-06-02T10:29:05Z","updated_at":"2017-06-02T10:29:05Z","body":"I use a workaround that I found elegant and allow to use all forms of boolean managed by Ansible.\r\nI understand that it does not cover all cases but it fits all of them in **my usage**.\r\n\r\n__CLI__:\r\n```\r\n-e \"myswitch=no\"\r\n```\r\n__In Ansible (playbook, default file, vars file)__:\r\n```\r\nmyswitch: yes\r\nmyvar: \"{{ 'value_true' if (myswitch | bool) else 'value_false' }}\"\r\n```"}}
{"actor":{"display_login":"Sabbasth"}}