<h5 dir="auto">ISSUE TYPE</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">core</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto">2.1</p>
<h5 dir="auto">CONFIGURATION</h5>
<h5 dir="auto">OS / ENVIRONMENT</h5>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto">if i got a line like this in <code class="notranslate">hosts</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="192.168.251.250 ansible_ssh_user=root ansible_ssh_pass=&quot;test#me&quot;"><pre class="notranslate"><code class="notranslate">192.168.251.250 ansible_ssh_user=root ansible_ssh_pass="test#me"
</code></pre></div>
<p dir="auto">and try to run a playbook against that host, im getting this failure</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#ansible-playbook test.yml -i hosts.test
Traceback (most recent call last):
  File &quot;/usr/local/src/ansible/bin/ansible-playbook&quot;, line 324, in &lt;module&gt;
    sys.exit(main(sys.argv[1:]))
  File &quot;/usr/local/src/ansible/bin/ansible-playbook&quot;, line 157, in main
    inventory = ansible.inventory.Inventory(options.inventory, vault_password=vault_pass)
  File &quot;/usr/local/src/ansible/lib/ansible/inventory/__init__.py&quot;, line 128, in __init__
    self.parser = InventoryParser(filename=host_list)
  File &quot;/usr/local/src/ansible/lib/ansible/inventory/ini.py&quot;, line 43, in __init__
    self._parse()
  File &quot;/usr/local/src/ansible/lib/ansible/inventory/ini.py&quot;, line 47, in _parse
    self._parse_base_groups()
  File &quot;/usr/local/src/ansible/lib/ansible/inventory/ini.py&quot;, line 108, in _parse_base_groups
    tokens = shlex.split(line)
  File &quot;/usr/lib/python2.7/shlex.py&quot;, line 279, in split
    return list(lex)
  File &quot;/usr/lib/python2.7/shlex.py&quot;, line 269, in next
    token = self.get_token()
  File &quot;/usr/lib/python2.7/shlex.py&quot;, line 96, in get_token
    raw = self.read_token()
  File &quot;/usr/lib/python2.7/shlex.py&quot;, line 172, in read_token
    raise ValueError, &quot;No closing quotation&quot;
ValueError: No closing quotation"><pre class="notranslate"><code class="notranslate">#ansible-playbook test.yml -i hosts.test
Traceback (most recent call last):
  File "/usr/local/src/ansible/bin/ansible-playbook", line 324, in &lt;module&gt;
    sys.exit(main(sys.argv[1:]))
  File "/usr/local/src/ansible/bin/ansible-playbook", line 157, in main
    inventory = ansible.inventory.Inventory(options.inventory, vault_password=vault_pass)
  File "/usr/local/src/ansible/lib/ansible/inventory/__init__.py", line 128, in __init__
    self.parser = InventoryParser(filename=host_list)
  File "/usr/local/src/ansible/lib/ansible/inventory/ini.py", line 43, in __init__
    self._parse()
  File "/usr/local/src/ansible/lib/ansible/inventory/ini.py", line 47, in _parse
    self._parse_base_groups()
  File "/usr/local/src/ansible/lib/ansible/inventory/ini.py", line 108, in _parse_base_groups
    tokens = shlex.split(line)
  File "/usr/lib/python2.7/shlex.py", line 279, in split
    return list(lex)
  File "/usr/lib/python2.7/shlex.py", line 269, in next
    token = self.get_token()
  File "/usr/lib/python2.7/shlex.py", line 96, in get_token
    raw = self.read_token()
  File "/usr/lib/python2.7/shlex.py", line 172, in read_token
    raise ValueError, "No closing quotation"
ValueError: No closing quotation
</code></pre></div>
<p dir="auto">when i removed the hash from the password, it all went away</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>
<h5 dir="auto">EXPECTED RESULTS</h5>
<h5 dir="auto">ACTUAL RESULTS</h5>
<p dir="auto">The character <code class="notranslate">#</code> is treated as a comment even if it is inside a string. As a consequence the rest of the command line gets stripped away and a <code class="notranslate">No closing quotation</code> error appears.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ cat _test.yml 

---
- hosts: all
  gather_facts: no
  tasks:
    - lineinfile: dest=/tmp/foo regexp=&quot;bar&quot; line=&quot;bar # comment about bar&quot;"><pre class="notranslate"><code class="notranslate">$ cat _test.yml 

---
- hosts: all
  gather_facts: no
  tasks:
    - lineinfile: dest=/tmp/foo regexp="bar" line="bar # comment about bar"
</code></pre></div>
<p dir="auto">With latest Ansible 1.2 development branch:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-playbook -vvv _test.yml 

PLAY [all] ******************************************************************** 

TASK: [lineinfile dest=/tmp/foo regexp=&quot;bar&quot; line=&quot;bar] *********************** 
&lt;xxx.lan&gt; ESTABLISH CONNECTION FOR USER: root on PORT 22 TO xxx.lan
&lt;xxx.lan&gt; EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-1366795278.56-129433001277548 &amp;&amp; chmod a+rx $HOME/.ansible/tmp/ansible-1366795278.56-129433001277548 &amp;&amp; echo $HOME/.ansible/tmp/ansible-1366795278.56-129433001277548'
&lt;xxx.lan&gt; REMOTE_MODULE lineinfile dest=/tmp/foo regexp=&quot;bar&quot; line=&quot;bar
&lt;xxx.lan&gt; PUT /tmp/tmp0GK3Pi TO /root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile
&lt;xxx.lan&gt; EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile; rm -rf /root/.ansible/tmp/ansible-1366795278.56-129433001277548/ &gt;/dev/null 2&gt;&amp;1'
failed: [xxx] =&gt; {&quot;failed&quot;: true, &quot;parsed&quot;: false}
invalid output was: Traceback (most recent call last):
  File &quot;/root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile&quot;, line 1167, in &lt;module&gt;
    main()
  File &quot;/root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile&quot;, line 293, in main
    supports_check_mode=True
  File &quot;/root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile&quot;, line 467, in __init__
    (self.params, self.args) = self._load_params()
  File &quot;/root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile&quot;, line 933, in _load_params
    items   = shlex.split(args)
  File &quot;/usr/lib/python2.7/shlex.py&quot;, line 279, in split
    return list(lex)
  File &quot;/usr/lib/python2.7/shlex.py&quot;, line 269, in next
    token = self.get_token()
  File &quot;/usr/lib/python2.7/shlex.py&quot;, line 96, in get_token
    raw = self.read_token()
  File &quot;/usr/lib/python2.7/shlex.py&quot;, line 172, in read_token
    raise ValueError, &quot;No closing quotation&quot;
ValueError: No closing quotation"><pre class="notranslate"><code class="notranslate">$ ansible-playbook -vvv _test.yml 

PLAY [all] ******************************************************************** 

TASK: [lineinfile dest=/tmp/foo regexp="bar" line="bar] *********************** 
&lt;xxx.lan&gt; ESTABLISH CONNECTION FOR USER: root on PORT 22 TO xxx.lan
&lt;xxx.lan&gt; EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-1366795278.56-129433001277548 &amp;&amp; chmod a+rx $HOME/.ansible/tmp/ansible-1366795278.56-129433001277548 &amp;&amp; echo $HOME/.ansible/tmp/ansible-1366795278.56-129433001277548'
&lt;xxx.lan&gt; REMOTE_MODULE lineinfile dest=/tmp/foo regexp="bar" line="bar
&lt;xxx.lan&gt; PUT /tmp/tmp0GK3Pi TO /root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile
&lt;xxx.lan&gt; EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile; rm -rf /root/.ansible/tmp/ansible-1366795278.56-129433001277548/ &gt;/dev/null 2&gt;&amp;1'
failed: [xxx] =&gt; {"failed": true, "parsed": false}
invalid output was: Traceback (most recent call last):
  File "/root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile", line 1167, in &lt;module&gt;
    main()
  File "/root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile", line 293, in main
    supports_check_mode=True
  File "/root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile", line 467, in __init__
    (self.params, self.args) = self._load_params()
  File "/root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile", line 933, in _load_params
    items   = shlex.split(args)
  File "/usr/lib/python2.7/shlex.py", line 279, in split
    return list(lex)
  File "/usr/lib/python2.7/shlex.py", line 269, in next
    token = self.get_token()
  File "/usr/lib/python2.7/shlex.py", line 96, in get_token
    raw = self.read_token()
  File "/usr/lib/python2.7/shlex.py", line 172, in read_token
    raise ValueError, "No closing quotation"
ValueError: No closing quotation
</code></pre></div>