<h4 dir="auto">ISSUE TYPE</h4>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">core, I think?</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.3.0.0
  config file = /Users/oliver/.ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.11 (default, Jan 22 2016, 08:29:18) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]"><pre class="notranslate"><code class="notranslate">ansible 2.3.0.0
  config file = /Users/oliver/.ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.11 (default, Jan 22 2016, 08:29:18) [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<p dir="auto">My ~/.ansible.cfg contains only the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[defaults]
transport=paramiko
timeout=60
remote_tmp = /tmp/.ansible/tmp"><pre class="notranslate"><code class="notranslate">[defaults]
transport=paramiko
timeout=60
remote_tmp = /tmp/.ansible/tmp
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">Running on macOS Sierra 10.12.4<br>
Managing OEL 6.4</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">I'm trying to specify a role dependency, giving a path to the dependency role that includes a variable defined in my <code class="notranslate">group_vars</code>, but I get <code class="notranslate">ERROR! 'common_roles_path' is undefined</code>. It only works if I define the variable in the play that uses the role.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<p dir="auto">My directory structure is as follows</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="common_roles/
  foo/
project/
  group_vars/
    all.yml
  roles/
    server/
       defaults/
          main.yml
       meta/
          main.yml
       tasks/
          main.yml
       vars/
          main.yml
  hosts
  sites.yml"><pre class="notranslate"><code class="notranslate">common_roles/
  foo/
project/
  group_vars/
    all.yml
  roles/
    server/
       defaults/
          main.yml
       meta/
          main.yml
       tasks/
          main.yml
       vars/
          main.yml
  hosts
  sites.yml
</code></pre></div>
<p dir="auto"><code class="notranslate">project/group_vars/all.yml</code>, <code class="notranslate">project/roles/server/defaults/main.yml</code> and <code class="notranslate">project/roles/server/vars/main.yml</code> all contain</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---

common_roles_path: &quot;{{ playbook_dir }}/../common_roles&quot;"><pre class="notranslate">---

<span class="pl-ent">common_roles_path</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ playbook_dir }}/../common_roles<span class="pl-pds">"</span></span></pre></div>
<p dir="auto"><code class="notranslate">project/roles/server/meta/main.yml</code> contains</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---

dependencies:
  - role: &quot;{{ common_roles_path }}/foo&quot;"><pre class="notranslate">---

<span class="pl-ent">dependencies</span>:
  - <span class="pl-ent">role</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ common_roles_path }}/foo<span class="pl-pds">"</span></span></pre></div>
<p dir="auto"><code class="notranslate">project/roles/server/tasks/main.yml</code> contains</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---

- include_role:
    name: &quot;{{ common_roles_path }}/foo&quot;"><pre class="notranslate">---

- <span class="pl-ent">include_role</span>:
    <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ common_roles_path }}/foo<span class="pl-pds">"</span></span></pre></div>
<p dir="auto"><code class="notranslate">project/hosts</code> contains</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[servers]
project.dev.vm"><pre class="notranslate"><code class="notranslate">[servers]
project.dev.vm
</code></pre></div>
<p dir="auto"><code class="notranslate">project/sites.yml</code> contains</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---

- name: Install project server
  hosts: servers
  roles:
    - server"><pre class="notranslate">---

- <span class="pl-ent">name</span>: <span class="pl-s">Install project server</span>
  <span class="pl-ent">hosts</span>: <span class="pl-s">servers</span>
  <span class="pl-ent">roles</span>:
    - <span class="pl-s">server</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">I expect the role at <code class="notranslate">common_roles/foo</code> to be executed as a dependency, then run again due to the <code class="notranslate">include_role</code> task.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">I get the following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook -vvvv -i hosts sites.yml
Using /Users/oliver/.ansible.cfg as config file
ERROR! 'common_roles_path' is undefined"><pre class="notranslate"><code class="notranslate">$ ansible-playbook -vvvv -i hosts sites.yml
Using /Users/oliver/.ansible.cfg as config file
ERROR! 'common_roles_path' is undefined
</code></pre></div>
<p dir="auto">However, if I modify <code class="notranslate">project/sites.yml</code> to contain</p>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---

- name: Install project server
  hosts: servers
  roles:
    - server
  vars:
    common_roles_path: &quot;{{ playbook_dir }}/../common_roles&quot;"><pre class="notranslate">---

- <span class="pl-ent">name</span>: <span class="pl-s">Install project server</span>
  <span class="pl-ent">hosts</span>: <span class="pl-s">servers</span>
  <span class="pl-ent">roles</span>:
    - <span class="pl-s">server</span>
  <span class="pl-ent">vars</span>:
    <span class="pl-ent">common_roles_path</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ playbook_dir }}/../common_roles<span class="pl-pds">"</span></span></pre></div>
<p dir="auto">then everything works as expected. It also works if I remove <code class="notranslate">project/roles/server/meta</code> and just rely on the <code class="notranslate">include_role</code> task (so the same variable used there is OK).</p>
<p dir="auto">The duplicate variable definitions in <code class="notranslate">project/roles/server/defaults</code> and <code class="notranslate">project/roles/server/vars</code> were only added to check if it was some scoping issue, their presence or absence makes no difference.</p>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">Modules using Python Lambda/Map functions</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible --version
ansible 2.2.1.0
  config file = /automation/ansible/playbooks/ansible.cfg
  configured module search path = ['library']"><pre class="notranslate"><code class="notranslate">ansible --version
ansible 2.2.1.0
  config file = /automation/ansible/playbooks/ansible.cfg
  configured module search path = ['library']
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[defaults]
forks = 50
transport = smart
gathering = explicit 
library = library
action_plugins = action_plugins
callback_plugins = callback_plugins
lookup_plugins = lookup_plugins
vars_plugins = vars_plugins
filter_plugins = filter_plugins
roles_path = roles:provisioning/roles
bin_ansible_callbacks = True
force_color = 1
host_key_checking = False
retry_files_enabled = False

[ssh_connection]
# Using control persist allows for connection re-use and can improve
# performance by a large margin, *IF* it is compatible with our setup
# -&gt; needs to be checked first...
ssh_args = -o ControlMaster=auto -o ControlPersist=1h -vvv
pipelining = True"><pre class="notranslate"><code class="notranslate">[defaults]
forks = 50
transport = smart
gathering = explicit 
library = library
action_plugins = action_plugins
callback_plugins = callback_plugins
lookup_plugins = lookup_plugins
vars_plugins = vars_plugins
filter_plugins = filter_plugins
roles_path = roles:provisioning/roles
bin_ansible_callbacks = True
force_color = 1
host_key_checking = False
retry_files_enabled = False

[ssh_connection]
# Using control persist allows for connection re-use and can improve
# performance by a large margin, *IF* it is compatible with our setup
# -&gt; needs to be checked first...
ssh_args = -o ControlMaster=auto -o ControlPersist=1h -vvv
pipelining = True
</code></pre></div>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<p dir="auto">CentOS 6.4</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">We are in process of upgrading our Ansible 1.8.2 code to Ansible 2.x.  We have custom Ansible modules that use common 'lambda' and 'map' Python functions to manipulate a list of instances (basically a list containing dictionaries). We noticed the lambda/map function combination is producing different results in Ansible 1.8.2 compared to Ansible 2.2.1.0.  Using Ansible 2.x the lambda/map functions do not result in changing the variable at all. However using Ansible 1.x the correct changes are done.  The Python version is the same for both Ansible 1.x and Ansible 2.x (Python 2.7.10).  The only changes are the necessary upgrades that are done using pip command to upgrade to Ansible 2.x.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">Create a custom module using the following code, and then call this module using a simple playbook with a task:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import traceback
def addme(i):
  i['my'] = 'test'

def main(module):
    result = {
      'changed': False,
      'timings': {}
    }

    try:
      x = [{&quot;example-key&quot;: &quot;example-value&quot;}]
      f = lambda i:addme(i)
      y = map(f, x)
      result['x'] = x
      result['y'] = str(y)
      module.exit_json(**result)
    except Exception:
      module.fail_json(msg=traceback.format_exc().splitlines())
   module.exit_json(**result)
}"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">traceback</span>
<span class="pl-k">def</span> <span class="pl-en">addme</span>(<span class="pl-s1">i</span>):
  <span class="pl-s1">i</span>[<span class="pl-s">'my'</span>] <span class="pl-c1">=</span> <span class="pl-s">'test'</span>

<span class="pl-k">def</span> <span class="pl-en">main</span>(<span class="pl-s1">module</span>):
    <span class="pl-s1">result</span> <span class="pl-c1">=</span> {
      <span class="pl-s">'changed'</span>: <span class="pl-c1">False</span>,
      <span class="pl-s">'timings'</span>: {}
    }

    <span class="pl-k">try</span>:
      <span class="pl-s1">x</span> <span class="pl-c1">=</span> [{<span class="pl-s">"example-key"</span>: <span class="pl-s">"example-value"</span>}]
      <span class="pl-s1">f</span> <span class="pl-c1">=</span> <span class="pl-k">lambda</span> <span class="pl-s1">i</span>:<span class="pl-en">addme</span>(<span class="pl-s1">i</span>)
      <span class="pl-s1">y</span> <span class="pl-c1">=</span> <span class="pl-en">map</span>(<span class="pl-s1">f</span>, <span class="pl-s1">x</span>)
      <span class="pl-s1">result</span>[<span class="pl-s">'x'</span>] <span class="pl-c1">=</span> <span class="pl-s1">x</span>
      <span class="pl-s1">result</span>[<span class="pl-s">'y'</span>] <span class="pl-c1">=</span> <span class="pl-en">str</span>(<span class="pl-s1">y</span>)
      <span class="pl-s1">module</span>.<span class="pl-en">exit_json</span>(<span class="pl-c1">**</span><span class="pl-s1">result</span>)
    <span class="pl-k">except</span> <span class="pl-v">Exception</span>:
      <span class="pl-s1">module</span>.<span class="pl-en">fail_json</span>(<span class="pl-s1">msg</span><span class="pl-c1">=</span><span class="pl-s1">traceback</span>.<span class="pl-en">format_exc</span>().<span class="pl-en">splitlines</span>())
   <span class="pl-s1">module</span>.<span class="pl-en">exit_json</span>(<span class="pl-c1">**</span><span class="pl-s1">result</span>)
}</pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>
<p dir="auto">We expect that the 'addme' function adds the key 'my' with value 'test' to the variable 'x'.<br>
Ansible 1.x produces this result, however Ansible 2.x does not add this key/value and does not have any errors at all.</p>
<p dir="auto">The results of 'x' should be:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    &quot;x&quot;: [
        {
            &quot;example-key&quot;: &quot;example-value&quot;,
            &quot;my&quot;: &quot;test&quot;
        }
    ],"><pre class="notranslate"><code class="notranslate">    "x": [
        {
            "example-key": "example-value",
            "my": "test"
        }
    ],
</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">Using Ansible 2.x we actually get no change to the 'x' variable:</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    &quot;x&quot;: [
        {
            &quot;example-key&quot;: &quot;example-value&quot;
        }
    ],"><pre class="notranslate"><code class="notranslate">    "x": [
        {
            "example-key": "example-value"
        }
    ],
</code></pre></div>