{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/15218","repository_url":"https://api.github.com/repos/ansible/ansible","labels_url":"https://api.github.com/repos/ansible/ansible/issues/15218/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/15218/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/15218/events","html_url":"https://github.com/ansible/ansible/issues/15218","id":144924839,"number":15218,"title":"Inconsistent behavior of when statement","user":{"login":"muziyoshiz","id":1255634,"avatar_url":"https://avatars.githubusercontent.com/u/1255634?v=3","gravatar_id":"","url":"https://api.github.com/users/muziyoshiz","html_url":"https://github.com/muziyoshiz","followers_url":"https://api.github.com/users/muziyoshiz/followers","following_url":"https://api.github.com/users/muziyoshiz/following{/other_user}","gists_url":"https://api.github.com/users/muziyoshiz/gists{/gist_id}","starred_url":"https://api.github.com/users/muziyoshiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muziyoshiz/subscriptions","organizations_url":"https://api.github.com/users/muziyoshiz/orgs","repos_url":"https://api.github.com/users/muziyoshiz/repos","events_url":"https://api.github.com/users/muziyoshiz/events{/privacy}","received_events_url":"https://api.github.com/users/muziyoshiz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-03-31T14:53:59Z","updated_at":"2016-04-01T13:21:27Z","closed_at":null,"body":"<!--- Verify first that your issue/request is not already reported in GitHub -->\r\n\r\n##### ISSUE TYPE\r\n<!--- Pick one below and delete the rest: -->\r\n - Bug Report\r\n\r\n##### ANSIBLE VERSION\r\n```\r\nansible 1.9.4\r\nansible 2.0.1.0\r\n```\r\n\r\n##### CONFIGURATION\r\n\r\nDefault of yum install\r\n\r\n##### OS / ENVIRONMENT\r\n\r\nCentOS Linux release 7.2.1511 (Core)\r\n\r\n##### SUMMARY and STEPS TO REPRODUCE\r\n<!--- Explain the problem briefly -->\r\n\r\nIf I write an inventory file and a task file as follows, `do_something.sh` is executed only on web1.example.com.\r\n\r\n```\r\n[webservers]\r\nweb1.example.com var1=true\r\nweb2.example.com var1=false\r\n```\r\n\r\n```yaml\r\n- command: /usr/bin/do_something.sh\r\n  when: var1\r\n```\r\n\r\nBut if I write an inventory file as follows:\r\n\r\n```yaml\r\n- command: /usr/bin/do_something.sh\r\n  when: var1 is defined and var1\r\n```\r\n\r\n`do_something.sh` is executed on both web1.example.com and web2.example.com.\r\n\r\nOf course, I know that all host variables defined in inventory files are treated as string variables. However, it does not explain this inconsistent behavior.\r\n\r\nHere is an example of task.yml: [ansible-2.0-sample/main.yml at master · muziyoshiz/ansible-2.0-sample](https://github.com/muziyoshiz/ansible-2.0-sample/blob/master/roles/webtier4/tasks/main.yml \"ansible-2.0-sample/main.yml at master · muziyoshiz/ansible-2.0-sample\")\r\n\r\n##### EXPECTED RESULTS\r\n\r\nIf `web2.example.com var1=false` is in the inventory file,\r\n\r\n* `when: var1` and `when: var1 is defined and var1` should be treated same as `when: false`\r\n\r\n<!--- What did you expect to happen when running the steps above? -->\r\n\r\n##### ACTUAL RESULTS\r\n<!--- What actually happened? If possible run with high verbosity (-vvvv) -->\r\n\r\nIf `web2.example.com var1=false` is in the inventory file,\r\n\r\n* `when: var1` was treated same as `when: false`\r\n* `when: var1 is defined and var1` was treated same as `when: true`"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/204394732","html_url":"https://github.com/ansible/ansible/issues/15218#issuecomment-204394732","issue_url":"https://api.github.com/repos/ansible/ansible/issues/15218","id":204394732,"user":{"login":"muziyoshiz","id":1255634,"avatar_url":"https://avatars.githubusercontent.com/u/1255634?v=3","gravatar_id":"","url":"https://api.github.com/users/muziyoshiz","html_url":"https://github.com/muziyoshiz","followers_url":"https://api.github.com/users/muziyoshiz/followers","following_url":"https://api.github.com/users/muziyoshiz/following{/other_user}","gists_url":"https://api.github.com/users/muziyoshiz/gists{/gist_id}","starred_url":"https://api.github.com/users/muziyoshiz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/muziyoshiz/subscriptions","organizations_url":"https://api.github.com/users/muziyoshiz/orgs","repos_url":"https://api.github.com/users/muziyoshiz/repos","events_url":"https://api.github.com/users/muziyoshiz/events{/privacy}","received_events_url":"https://api.github.com/users/muziyoshiz/received_events","type":"User","site_admin":false},"created_at":"2016-04-01T13:21:27Z","updated_at":"2016-04-01T13:21:27Z","body":"Thanks for your reply.\r\nI wrote `localhost var1=True` or `localhost var1=False` in my inventory file, and tried again. The following is the result.\r\n\r\n| when statement                                | var1=true  | var1=false | var1=True  | var1=False |\r\n|-----------------------------------------------|------------|------------|------------|------------|\r\n| `when: var1 is defined`                       | ok         | ok         | ok         | ok         |\r\n| `when: var1`                                  | ok         | skipping (inconsistent)  | ok         | skipping   |\r\n| `when: var1 \\| bool`                          | ok         | skipping   | ok         | skipping   |\r\n| `when: var1 is defined and var1`              | ok         | ok (inconsistent)        | ok         | skipping   |\r\n| `when: var1 is defined and var1 \\| bool`      | ok         | skipping   | ok         | skipping   |\r\n\r\nI understood that True/False should be used in my inventory file when I want boolean.\r\nHowever now I still wonder why `when: var1` and `when: var1 is defined and var1` show different behavior."}}