title: Do task if custom variable is set to true
body: <p>I would like to do a task if and only if a custom variable (from the, main, playbook.yml) is set to true. I've had a couple of attempts at it, but none worked.</p>
  
  <p>Here's my latest attempt:</p>
  
  <p>In <code>tasks/main.yml</code>:</p>
  
  <pre><code>- name: Unpack Nexus main configurations
    unarchive:
      src="{{ nexus_configs_download_dir }}/{{ nexus_main_configurations }}"
      dest="{{ nexus_installation_dir }}"
      creates="{{ nexus_installation_dir }}/nexus-professional-{{ nexus_version }}"
      force=no
      copy=false
      owner={{ nexus_os_user }}
      group={{ nexus_os_group }}
      mode="0755"
    when: "{{ nexus_main_select_configuration | True }}"
    tags: 
      - unpack
      - ansible-nexus
  
  - name: Unpack Nexus sync configurations
    unarchive:
      src="{{ nexus_configs_download_dir }}/{{ nexus_sync_configurations }}"
      dest="{{ nexus_installation_dir }}"
      creates="{{ nexus_installation_dir }}/nexus-professional-{{ nexus_version }}"
      force=no
      copy=false
      owner={{ nexus_os_user }}
      group={{ nexus_os_group }}
      mode="0755"
    when: "{{ nexus_sync_select_configuration | True }}"
    tags: 
      - unpack
      - ansible-nexus
  
  - name: Unpack Nexus proxy configurations
    unarchive:
      src="{{ nexus_configs_download_dir }}/{{ nexus_proxy_configurations }}"
      dest="{{ nexus_installation_dir }}"
      creates="{{ nexus_installation_dir }}/nexus-professional-{{ nexus_version }}"
      force=no
      copy=false
      owner={{ nexus_os_user }}
      group={{ nexus_os_group }}
      mode="0755"
    when: "{{ nexus_proxy_select_configuration | True }}"
    tags: 
      - unpack
      - ansible-nexus
  </code></pre>
  
  <p>In <code>defaults/main.yml</code>:</p>
  
  <pre><code>---
  # [REDACTED]
  nexus_installation_dir: '/usr/share'
  nexus_main: false
  nexus_sync: false
  nexus_proxy: false
  nexus_main_select_configuration: "{{ nexus_main | bool }}"
  nexus_sync_select_configuration: "{{ nexus_sync | bool }}"
  nexus_proxy_select_configuration: "{{ nexus_proxy | bool }}"
  </code></pre>
  
  <p>In the main <code>playbook.yml</code>:</p>
  
  <pre><code>---
  
  - hosts: 127.0.0.1
    connection: local
    roles:
    - { role: covs.nexus,
        nexus_version: '2.14.1-01',
        nexus_installation_dir: '/opt',
        nexus_port: 8080,
        nexus_webapp_context_path: '/',
        nexus_proxy: true,
        become: yes}
  </code></pre>
  
  <p>I get the following error with this latest attempt:</p>
  
  <pre><code>TASK [covs.nexus : Unpack Nexus main configurations] ***************************
  fatal: [127.0.0.1]: FAILED! =&gt; {"failed": true, "msg": "The conditional check '{{ nexus_main_select_configuration | True }}' failed. The error was: template error while templating string: no filter named 'True'. String: {{ nexus_main_select_configuration | True }}\n\nThe error appears to have been in '/home/ubuntu/covs-nexus-ansible/tasks/main.yml': line 276, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Unpack Nexus main configurations\n  ^ here\n"}
  </code></pre>
  
  <p>I was trying to get help from <a href="http://docs.ansible.com/ansible/playbooks_conditionals.html" rel="nofollow noreferrer">this page</a> but their examples are based on running a command on the machine then based on that command do something. I could not find an example of conditionals based on a variable from another yml file in the playbook.</p>