<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<ul dir="auto">
<li>modules/web_infrastructure/apache2_module.py</li>
</ul>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.4.0.0
  config file = None
  configured module search path = [u'/Users/*****/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Python/2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.10 (default, Jul 15 2017, 17:16:57) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]"><pre class="notranslate"><code class="notranslate">ansible 2.4.0.0
  config file = None
  configured module search path = [u'/Users/*****/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Python/2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.10 (default, Jul 15 2017, 17:16:57) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">Empty</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<h5 dir="auto">SUMMARY</h5>

<p dir="auto">When enabling php5 on a 14.04 system an exception is thrown.</p>
<p dir="auto">I believe the issue has to do with the variable not being checked for Noneness first:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    for search, reexpr in re_workarounds:
        if search in name:
            rematch = re.search(reexpr, name)
            return rematch.group(1) + '_module'"><pre class="notranslate">    <span class="pl-k">for</span> <span class="pl-s1">search</span>, <span class="pl-s1">reexpr</span> <span class="pl-c1">in</span> <span class="pl-s1">re_workarounds</span>:
        <span class="pl-k">if</span> <span class="pl-s1">search</span> <span class="pl-c1">in</span> <span class="pl-s1">name</span>:
            <span class="pl-s1">rematch</span> <span class="pl-c1">=</span> <span class="pl-s1">re</span>.<span class="pl-en">search</span>(<span class="pl-s1">reexpr</span>, <span class="pl-s1">name</span>)
            <span class="pl-k">return</span> <span class="pl-s1">rematch</span>.<span class="pl-en">group</span>(<span class="pl-c1">1</span>) <span class="pl-c1">+</span> <span class="pl-s">'_module'</span></pre></div>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="apache_php_install_modules:
  - php5
  - libapache2-mod-php5

apache_php_enable_module: php5.0

- name: Install php modules
  package:
    name: &quot;{{ item }}&quot;
    state: present
  with_items: &quot;{{ apache_php_install_modules }}&quot;
  tags:
    php
    scgi

- name: Enable apache modules
  apache2_module:
    name: &quot;{{ item }}&quot;
    state: present
  with_items:
    - scgi
    - &quot;{{ apache_php_enable_module }}&quot;
  notify:
    - Restart apache
  tags:
    php
    scgi"><pre class="notranslate"><span class="pl-ent">apache_php_install_modules</span>:
  - <span class="pl-s">php5</span>
  - <span class="pl-s">libapache2-mod-php5</span>

<span class="pl-ent">apache_php_enable_module</span>: <span class="pl-s">php5.0</span>

- <span class="pl-ent">name</span>: <span class="pl-s">Install php modules</span>
  <span class="pl-ent">package</span>:
    <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">state</span>: <span class="pl-s">present</span>
  <span class="pl-ent">with_items</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ apache_php_install_modules }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">tags</span>:
    <span class="pl-s">php</span>
    <span class="pl-s">scgi</span>

- <span class="pl-ent">name</span>: <span class="pl-s">Enable apache modules</span>
  <span class="pl-ent">apache2_module</span>:
    <span class="pl-ent">name</span>: <span class="pl-s"><span class="pl-pds">"</span>{{ item }}<span class="pl-pds">"</span></span>
    <span class="pl-ent">state</span>: <span class="pl-s">present</span>
  <span class="pl-ent">with_items</span>:
    - <span class="pl-s">scgi</span>
    - <span class="pl-s"><span class="pl-pds">"</span>{{ apache_php_enable_module }}<span class="pl-pds">"</span></span>
  <span class="pl-ent">notify</span>:
    - <span class="pl-s">Restart apache</span>
  <span class="pl-ent">tags</span>:
    <span class="pl-s">php</span>
    <span class="pl-s">scgi</span></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">either "ok" or "changed"</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">Exception is thrown</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Using module file /home/travis/virtualenv/python2.7.13/lib/python2.7/site-packages/ansible/modules/web_infrastructure/apache2_module.py
&lt;localhost&gt; EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
&lt;localhost&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p &quot;` echo /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497 `&quot; &amp;&amp; echo ansible-tmp-1506660428.72-709978674497=&quot;` echo /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497 `&quot; ) &amp;&amp; sleep 0'
&lt;localhost&gt; PUT /tmp/tmpiUGMfp TO /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497/apache2_module.py
&lt;localhost&gt; EXEC /bin/sh -c 'chmod u+x /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497/ /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497/apache2_module.py &amp;&amp; sleep 0'
&lt;localhost&gt; EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '&quot;'&quot;'echo BECOME-SUCCESS-rghrccwwnwgddngdcsfajyicavcmatch; /usr/bin/python /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497/apache2_module.py; rm -rf &quot;/home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497/&quot; &gt; /dev/null 2&gt;&amp;1'&quot;'&quot;' &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
  File &quot;/tmp/ansible_2VMVXu/ansible_module_apache2_module.py&quot;, line 238, in &lt;module&gt;
    main()
  File &quot;/tmp/ansible_2VMVXu/ansible_module_apache2_module.py&quot;, line 233, in main
    _set_state(module, module.params['state'])
  File &quot;/tmp/ansible_2VMVXu/ansible_module_apache2_module.py&quot;, line 184, in _set_state
    if _module_is_enabled(module) != want_enabled:
  File &quot;/tmp/ansible_2VMVXu/ansible_module_apache2_module.py&quot;, line 141, in _module_is_enabled
    searchstring = ' ' + create_apache_identifier(name)
  File &quot;/tmp/ansible_2VMVXu/ansible_module_apache2_module.py&quot;, line 170, in create_apache_identifier
    return rematch.group(1) + '_module'
AttributeError: 'NoneType' object has no attribute 'group'
failed: [localhost] (item=php5) =&gt; {
    &quot;changed&quot;: false, 
    &quot;failed&quot;: true, 
    &quot;item&quot;: &quot;php5&quot;, 
    &quot;module_stderr&quot;: &quot;Traceback (most recent call last):\n  File \&quot;/tmp/ansible_2VMVXu/ansible_module_apache2_module.py\&quot;, line 238, in &lt;module&gt;\n    main()\n  File \&quot;/tmp/ansible_2VMVXu/ansible_module_apache2_module.py\&quot;, line 233, in main\n    _set_state(module, module.params['state'])\n  File \&quot;/tmp/ansible_2VMVXu/ansible_module_apache2_module.py\&quot;, line 184, in _set_state\n    if _module_is_enabled(module) != want_enabled:\n  File \&quot;/tmp/ansible_2VMVXu/ansible_module_apache2_module.py\&quot;, line 141, in _module_is_enabled\n    searchstring = ' ' + create_apache_identifier(name)\n  File \&quot;/tmp/ansible_2VMVXu/ansible_module_apache2_module.py\&quot;, line 170, in create_apache_identifier\n    return rematch.group(1) + '_module'\nAttributeError: 'NoneType' object has no attribute 'group'\n&quot;, 
    &quot;module_stdout&quot;: &quot;&quot;, 
    &quot;msg&quot;: &quot;MODULE FAILURE&quot;, 
    &quot;rc&quot;: 0
}"><pre class="notranslate"><code class="notranslate">Using module file /home/travis/virtualenv/python2.7.13/lib/python2.7/site-packages/ansible/modules/web_infrastructure/apache2_module.py
&lt;localhost&gt; EXEC /bin/sh -c 'echo ~ &amp;&amp; sleep 0'
&lt;localhost&gt; EXEC /bin/sh -c '( umask 77 &amp;&amp; mkdir -p "` echo /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497 `" &amp;&amp; echo ansible-tmp-1506660428.72-709978674497="` echo /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497 `" ) &amp;&amp; sleep 0'
&lt;localhost&gt; PUT /tmp/tmpiUGMfp TO /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497/apache2_module.py
&lt;localhost&gt; EXEC /bin/sh -c 'chmod u+x /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497/ /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497/apache2_module.py &amp;&amp; sleep 0'
&lt;localhost&gt; EXEC /bin/sh -c 'sudo -H -S -n -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-rghrccwwnwgddngdcsfajyicavcmatch; /usr/bin/python /home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497/apache2_module.py; rm -rf "/home/travis/.ansible/tmp/ansible-tmp-1506660428.72-709978674497/" &gt; /dev/null 2&gt;&amp;1'"'"' &amp;&amp; sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_2VMVXu/ansible_module_apache2_module.py", line 238, in &lt;module&gt;
    main()
  File "/tmp/ansible_2VMVXu/ansible_module_apache2_module.py", line 233, in main
    _set_state(module, module.params['state'])
  File "/tmp/ansible_2VMVXu/ansible_module_apache2_module.py", line 184, in _set_state
    if _module_is_enabled(module) != want_enabled:
  File "/tmp/ansible_2VMVXu/ansible_module_apache2_module.py", line 141, in _module_is_enabled
    searchstring = ' ' + create_apache_identifier(name)
  File "/tmp/ansible_2VMVXu/ansible_module_apache2_module.py", line 170, in create_apache_identifier
    return rematch.group(1) + '_module'
AttributeError: 'NoneType' object has no attribute 'group'
failed: [localhost] (item=php5) =&gt; {
    "changed": false, 
    "failed": true, 
    "item": "php5", 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_2VMVXu/ansible_module_apache2_module.py\", line 238, in &lt;module&gt;\n    main()\n  File \"/tmp/ansible_2VMVXu/ansible_module_apache2_module.py\", line 233, in main\n    _set_state(module, module.params['state'])\n  File \"/tmp/ansible_2VMVXu/ansible_module_apache2_module.py\", line 184, in _set_state\n    if _module_is_enabled(module) != want_enabled:\n  File \"/tmp/ansible_2VMVXu/ansible_module_apache2_module.py\", line 141, in _module_is_enabled\n    searchstring = ' ' + create_apache_identifier(name)\n  File \"/tmp/ansible_2VMVXu/ansible_module_apache2_module.py\", line 170, in create_apache_identifier\n    return rematch.group(1) + '_module'\nAttributeError: 'NoneType' object has no attribute 'group'\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}
</code></pre></div>
<h5 dir="auto">ISSUE TYPE</h5>
<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">apache2_module</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 2.4.0.0
  config file = /home/ps/.ansible.cfg
  configured module search path = [u'/home/ps/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]"><pre class="notranslate"><code class="notranslate">ansible 2.4.0.0
  config file = /home/ps/.ansible.cfg
  configured module search path = [u'/home/ps/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<h5 dir="auto">OS / ENVIRONMENT</h5>

<h5 dir="auto">SUMMARY</h5>

<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="apache_modules:
  - php5"><pre class="notranslate"><span class="pl-ent">apache_modules</span>:
  - <span class="pl-s">php5</span></pre></div>
<h5 dir="auto">EXPECTED RESULTS</h5>

<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/web_infrastructure/apache2_module.py
&lt;1.2.3.4&gt; ESTABLISH SSH CONNECTION FOR USER: ansible
&lt;1.2.3.4&gt; SSH: EXEC ssh -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=60 -o 'ControlPath=~/.ssh/ansible-ssh-%h-%p-%r' 1.2.3.4 '/bin/sh -c '&quot;'&quot;'( umask 77 &amp;&amp; mkdir -p &quot;` echo $HOME/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952 `&quot; &amp;&amp; echo ansible-tmp-1506328589.49-122064381956952=&quot;` echo $HOME/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952 `&quot; ) &amp;&amp; sleep 0'&quot;'&quot;''
&lt;1.2.3.4&gt; (0, 'ansible-tmp-1506328589.49-122064381956952=/home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952\n', '')
&lt;1.2.3.4&gt; PUT /tmp/tmpP42OZP TO /home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/apache2_module.py
&lt;1.2.3.4&gt; SSH: EXEC sftp -b - -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=60 -o 'ControlPath=~/.ssh/ansible-ssh-%h-%p-%r' '[1.2.3.4]'
&lt;1.2.3.4&gt; (0, 'sftp&gt; put /tmp/tmpP42OZP /home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/apache2_module.py\n', '')
&lt;1.2.3.4&gt; ESTABLISH SSH CONNECTION FOR USER: ansible
&lt;1.2.3.4&gt; SSH: EXEC ssh -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=60 -o 'ControlPath=~/.ssh/ansible-ssh-%h-%p-%r' 1.2.3.4 '/bin/sh -c '&quot;'&quot;'chmod u+x /home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/ /home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/apache2_module.py &amp;&amp; sleep 0'&quot;'&quot;''
&lt;1.2.3.4&gt; (0, '', '')
&lt;1.2.3.4&gt; ESTABLISH SSH CONNECTION FOR USER: ansible
&lt;1.2.3.4&gt; SSH: EXEC ssh -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=60 -o 'ControlPath=~/.ssh/ansible-ssh-%h-%p-%r' -tt 1.2.3.4 '/bin/sh -c '&quot;'&quot;'sudo -H -S  -p &quot;[sudo via ansible, key=gbfxlqwavpoyetsyizstcudrknzonvlx] password: &quot; -u root /bin/sh -c '&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'echo BECOME-SUCCESS-gbfxlqwavpoyetsyizstcudrknzonvlx; /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/apache2_module.py; rm -rf &quot;/home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/&quot; &gt; /dev/null 2&gt;&amp;1'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;'&quot;' &amp;&amp; sleep 0'&quot;'&quot;''
&lt;1.2.3.4&gt; (0, '\r\nTraceback (most recent call last):\r\n  File &quot;/tmp/ansible_m43APd/ansible_module_apache2_module.py&quot;, line 238, in &lt;module&gt;\r\n    main()\r\n  File &quot;/tmp/ansible_m43APd/ansible_module_apache2_module.py&quot;, line 233, in main\r\n    _set_state(module, module.params[\'state\'])\r\n  File &quot;/tmp/ansible_m43APd/ansible_module_apache2_module.py&quot;, line 184, in _set_state\r\n    if _module_is_enabled(module) != want_enabled:\r\n  File &quot;/tmp/ansible_m43APd/ansible_module_apache2_module.py&quot;, line 141, in _module_is_enabled\r\n    searchstring = \' \' + create_apache_identifier(name)\r\n  File &quot;/tmp/ansible_m43APd/ansible_module_apache2_module.py&quot;, line 170, in create_apache_identifier\r\n    return rematch.group(1) + \'_module\'\r\nAttributeError: \'NoneType\' object has no attribute \'group\'\r\n', 'Shared connection to 1.2.3.4 closed.\r\n')
failed: [test-host] (item=php5) =&gt; {
    &quot;changed&quot;: false, 
    &quot;failed&quot;: true, 
    &quot;item&quot;: &quot;php5&quot;, 
    &quot;module_stderr&quot;: &quot;Shared connection to 1.2.3.4 closed.\r\n&quot;, 
    &quot;module_stdout&quot;: &quot;\r\nTraceback (most recent call last):\r\n  File \&quot;/tmp/ansible_m43APd/ansible_module_apache2_module.py\&quot;, line 238, in &lt;module&gt;\r\n    main()\r\n  File \&quot;/tmp/ansible_m43APd/ansible_module_apache2_module.py\&quot;, line 233, in main\r\n    _set_state(module, module.params['state'])\r\n  File \&quot;/tmp/ansible_m43APd/ansible_module_apache2_module.py\&quot;, line 184, in _set_state\r\n    if _module_is_enabled(module) != want_enabled:\r\n  File \&quot;/tmp/ansible_m43APd/ansible_module_apache2_module.py\&quot;, line 141, in _module_is_enabled\r\n    searchstring = ' ' + create_apache_identifier(name)\r\n  File \&quot;/tmp/ansible_m43APd/ansible_module_apache2_module.py\&quot;, line 170, in create_apache_identifier\r\n    return rematch.group(1) + '_module'\r\nAttributeError: 'NoneType' object has no attribute 'group'\r\n&quot;, 
    &quot;msg&quot;: &quot;MODULE FAILURE&quot;, 
    &quot;rc&quot;: 0
}"><pre class="notranslate"><code class="notranslate">Using module file /usr/local/lib/python2.7/dist-packages/ansible/modules/web_infrastructure/apache2_module.py
&lt;1.2.3.4&gt; ESTABLISH SSH CONNECTION FOR USER: ansible
&lt;1.2.3.4&gt; SSH: EXEC ssh -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=60 -o 'ControlPath=~/.ssh/ansible-ssh-%h-%p-%r' 1.2.3.4 '/bin/sh -c '"'"'( umask 77 &amp;&amp; mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952 `" &amp;&amp; echo ansible-tmp-1506328589.49-122064381956952="` echo $HOME/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952 `" ) &amp;&amp; sleep 0'"'"''
&lt;1.2.3.4&gt; (0, 'ansible-tmp-1506328589.49-122064381956952=/home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952\n', '')
&lt;1.2.3.4&gt; PUT /tmp/tmpP42OZP TO /home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/apache2_module.py
&lt;1.2.3.4&gt; SSH: EXEC sftp -b - -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=60 -o 'ControlPath=~/.ssh/ansible-ssh-%h-%p-%r' '[1.2.3.4]'
&lt;1.2.3.4&gt; (0, 'sftp&gt; put /tmp/tmpP42OZP /home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/apache2_module.py\n', '')
&lt;1.2.3.4&gt; ESTABLISH SSH CONNECTION FOR USER: ansible
&lt;1.2.3.4&gt; SSH: EXEC ssh -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=60 -o 'ControlPath=~/.ssh/ansible-ssh-%h-%p-%r' 1.2.3.4 '/bin/sh -c '"'"'chmod u+x /home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/ /home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/apache2_module.py &amp;&amp; sleep 0'"'"''
&lt;1.2.3.4&gt; (0, '', '')
&lt;1.2.3.4&gt; ESTABLISH SSH CONNECTION FOR USER: ansible
&lt;1.2.3.4&gt; SSH: EXEC ssh -o ControlMaster=auto -o ControlPersist=60s -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=60 -o 'ControlPath=~/.ssh/ansible-ssh-%h-%p-%r' -tt 1.2.3.4 '/bin/sh -c '"'"'sudo -H -S  -p "[sudo via ansible, key=gbfxlqwavpoyetsyizstcudrknzonvlx] password: " -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-gbfxlqwavpoyetsyizstcudrknzonvlx; /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/apache2_module.py; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1506328589.49-122064381956952/" &gt; /dev/null 2&gt;&amp;1'"'"'"'"'"'"'"'"' &amp;&amp; sleep 0'"'"''
&lt;1.2.3.4&gt; (0, '\r\nTraceback (most recent call last):\r\n  File "/tmp/ansible_m43APd/ansible_module_apache2_module.py", line 238, in &lt;module&gt;\r\n    main()\r\n  File "/tmp/ansible_m43APd/ansible_module_apache2_module.py", line 233, in main\r\n    _set_state(module, module.params[\'state\'])\r\n  File "/tmp/ansible_m43APd/ansible_module_apache2_module.py", line 184, in _set_state\r\n    if _module_is_enabled(module) != want_enabled:\r\n  File "/tmp/ansible_m43APd/ansible_module_apache2_module.py", line 141, in _module_is_enabled\r\n    searchstring = \' \' + create_apache_identifier(name)\r\n  File "/tmp/ansible_m43APd/ansible_module_apache2_module.py", line 170, in create_apache_identifier\r\n    return rematch.group(1) + \'_module\'\r\nAttributeError: \'NoneType\' object has no attribute \'group\'\r\n', 'Shared connection to 1.2.3.4 closed.\r\n')
failed: [test-host] (item=php5) =&gt; {
    "changed": false, 
    "failed": true, 
    "item": "php5", 
    "module_stderr": "Shared connection to 1.2.3.4 closed.\r\n", 
    "module_stdout": "\r\nTraceback (most recent call last):\r\n  File \"/tmp/ansible_m43APd/ansible_module_apache2_module.py\", line 238, in &lt;module&gt;\r\n    main()\r\n  File \"/tmp/ansible_m43APd/ansible_module_apache2_module.py\", line 233, in main\r\n    _set_state(module, module.params['state'])\r\n  File \"/tmp/ansible_m43APd/ansible_module_apache2_module.py\", line 184, in _set_state\r\n    if _module_is_enabled(module) != want_enabled:\r\n  File \"/tmp/ansible_m43APd/ansible_module_apache2_module.py\", line 141, in _module_is_enabled\r\n    searchstring = ' ' + create_apache_identifier(name)\r\n  File \"/tmp/ansible_m43APd/ansible_module_apache2_module.py\", line 170, in create_apache_identifier\r\n    return rematch.group(1) + '_module'\r\nAttributeError: 'NoneType' object has no attribute 'group'\r\n", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}
</code></pre></div>
<p dir="auto">Most probably this part of code is the issue.<br>
ansible 2.3.2</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;&quot;&quot;
Work around for php modules; php7.x are always listed as php7_module
&quot;&quot;&quot;
php_module = re.search(r'^(php\d)\.', name)
if php_module:
    name = php_module.group(1)"><pre class="notranslate"><code class="notranslate">"""
Work around for php modules; php7.x are always listed as php7_module
"""
php_module = re.search(r'^(php\d)\.', name)
if php_module:
    name = php_module.group(1)
</code></pre></div>
<p dir="auto">ansible 2.4.0</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# re expressions to extract subparts of names
re_workarounds = [
    ('php', r'^(php\d)\.'),
]

for a2enmod_spelling, module_name in text_workarounds:
    if a2enmod_spelling in name:
        return module_name

for search, reexpr in re_workarounds:
    if search in name:
        rematch = re.search(reexpr, name)
        return rematch.group(1) + '_module'

return name + '_module'"><pre class="notranslate"><code class="notranslate"># re expressions to extract subparts of names
re_workarounds = [
    ('php', r'^(php\d)\.'),
]

for a2enmod_spelling, module_name in text_workarounds:
    if a2enmod_spelling in name:
        return module_name

for search, reexpr in re_workarounds:
    if search in name:
        rematch = re.search(reexpr, name)
        return rematch.group(1) + '_module'

return name + '_module'
</code></pre></div>