Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

core

ANSIBLE VERSION

2.1

CONFIGURATION

OS / ENVIRONMENT

SUMMARY

if i got a line like this in hosts

192.168.251.250 ansible_ssh_user=root ansible_ssh_pass="test#me"

and try to run a playbook against that host, im getting this failure

#ansible-playbook test.yml -i hosts.test
Traceback (most recent call last):
File "/usr/local/src/ansible/bin/ansible-playbook", line 324, in <module>
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

when i removed the hash from the password, it all went away

STEPS TO REPRODUCE

EXPECTED RESULTS

ACTUAL RESULTS

Issue 2:
The character # 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 No closing quotation error appears.

$ cat _test.yml

---
- hosts: all
gather_facts: no
tasks:
- lineinfile: dest=/tmp/foo regexp="bar" line="bar # comment about bar"

With latest Ansible 1.2 development branch:

$ ansible-playbook -vvv _test.yml

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

TASK: [lineinfile dest=/tmp/foo regexp="bar" line="bar] ***********************
<xxx.lan> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO xxx.lan
<xxx.lan> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-1366795278.56-129433001277548 && chmod a+rx $HOME/.ansible/tmp/ansible-1366795278.56-129433001277548 && echo $HOME/.ansible/tmp/ansible-1366795278.56-129433001277548'
<xxx.lan> REMOTE_MODULE lineinfile dest=/tmp/foo regexp="bar" line="bar
<xxx.lan> PUT /tmp/tmp0GK3Pi TO /root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile
<xxx.lan> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile; rm -rf /root/.ansible/tmp/ansible-1366795278.56-129433001277548/ >/dev/null 2>&1'
failed: [xxx] => {"failed": true, "parsed": false}
invalid output was: Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-1366795278.56-129433001277548/lineinfile", line 1167, in <module>
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