<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ansible 0.8 (devel 761330b125) last updated 2012/10/04 09:19:51 (GMT +200)"><pre class="notranslate"><code class="notranslate">ansible 0.8 (devel 761330b125) last updated 2012/10/04 09:19:51 (GMT +200)
</code></pre></div>
<p dir="auto">host variables specified in inventory file aren't stored in <em>hostvars</em>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ cat hosts
[local]
127.0.0.1 person=&quot;John.Q&quot; ansible_python_interpreter=/usr/bin/python xxxx=&quot;foo&quot;"><pre class="notranslate"><code class="notranslate">$ cat hosts
[local]
127.0.0.1 person="John.Q" ansible_python_interpreter=/usr/bin/python xxxx="foo"
</code></pre></div>
<div class="highlight highlight-source-yaml notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="
---
- hosts: 127.0.0.1
  gather_facts: false
  connection: local
  tasks:
    - action: template src=templ.in dest=/tmp/t"><pre class="notranslate">---
- <span class="pl-ent">hosts</span>: <span class="pl-s">127.0.0.1</span>
  <span class="pl-ent">gather_facts</span>: <span class="pl-c1">false</span>
  <span class="pl-ent">connection</span>: <span class="pl-s">local</span>
  <span class="pl-ent">tasks</span>:
    - <span class="pl-ent">action</span>: <span class="pl-s">template src=templ.in dest=/tmp/t</span></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ cat templ.in
{{ hostvars | to_json }}"><pre class="notranslate"><code class="notranslate">$ cat templ.in
{{ hostvars | to_json }}
</code></pre></div>
<p dir="auto">produces no mention of either <em>person</em>, <em>ansible_python_interpreter</em> or <em>xxxx</em>.</p>
<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/simonpie/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/simonpie">@simonpie</a> on 2016-08-22T19:28:14Z</p>

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

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

<ul dir="auto">
<li>lineinfile</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.1.1.0
  config file = /Users/simonpie/Documents/WSO2/1.10/Ansible/ansible.cfg
  configured module search path = Default w/o overrides"><pre class="notranslate"><code class="notranslate">ansible 2.1.1.0
  config file = /Users/simonpie/Documents/WSO2/1.10/Ansible/ansible.cfg
  configured module search path = Default w/o overrides
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

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

<p dir="auto">The basic ansible version installed by brew on a fully patch El Capitan Mac controlling an oracle linux vm.</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">When trying to insert a convoluted line using the lineinfile module, outer quotes are printed in the file whilst they should not be.  I can go around the problem by using variables.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="- name: Minimum example of failure for lineinfile module
  hosts: wso2
  vars:
    wso2Home: ~wso2/WSO2API/wso2am-1.10.0
    testString: &quot;    -Djava.util.prefs.userRoot=\&quot;/home/wso2/.java/.userPrefsJijJa\&quot; \x5C&quot;

  become: yes
  become_user: root

  tasks:

      - name: Ajout des repertoires de prefs java Not OK
        lineinfile: dest={{wso2Home}}/bin/test-wso2server.sh line=&quot;    -Djava.util.prefs.userRoot=\&quot;/home/wso2/.java/.userPrefs\&quot; \x5C&quot; insertafter='^(\s*)-Djava.util.logging.config.file(.*)'

      - name: Ajout des repertoires de prefs java OK
        lineinfile: dest={{wso2Home}}/bin/test-wso2server.sh line={{testString}} insertafter='^(\s*)-Djava.util.logging.config.file(.*)'"><pre class="notranslate"><code class="notranslate">- name: Minimum example of failure for lineinfile module
  hosts: wso2
  vars:
    wso2Home: ~wso2/WSO2API/wso2am-1.10.0
    testString: "    -Djava.util.prefs.userRoot=\"/home/wso2/.java/.userPrefsJijJa\" \x5C"

  become: yes
  become_user: root

  tasks:

      - name: Ajout des repertoires de prefs java Not OK
        lineinfile: dest={{wso2Home}}/bin/test-wso2server.sh line="    -Djava.util.prefs.userRoot=\"/home/wso2/.java/.userPrefs\" \x5C" insertafter='^(\s*)-Djava.util.logging.config.file(.*)'

      - name: Ajout des repertoires de prefs java OK
        lineinfile: dest={{wso2Home}}/bin/test-wso2server.sh line={{testString}} insertafter='^(\s*)-Djava.util.logging.config.file(.*)'
</code></pre></div>
<p dir="auto">Use the following file as destination</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="do
    $JAVACMD \
    -Xbootclasspath/a:&quot;$CARBON_XBOOTCLASSPATH&quot; \
    $JVM_MEM_OPTS \
    -XX:+HeapDumpOnOutOfMemoryError \
    -XX:HeapDumpPath=&quot;$CARBON_HOME/repository/logs/heap-dump.hprof&quot; \
    $JAVA_OPTS \
    -Djava.util.logging.config.file=&quot;$CARBON_HOME/repository/conf/etc/logging-bridge.properties&quot; \
    -DworkerNode=false \
    org.wso2.carbon.bootstrap.Bootstrap $*
    status=$?
done"><pre class="notranslate"><code class="notranslate">do
    $JAVACMD \
    -Xbootclasspath/a:"$CARBON_XBOOTCLASSPATH" \
    $JVM_MEM_OPTS \
    -XX:+HeapDumpOnOutOfMemoryError \
    -XX:HeapDumpPath="$CARBON_HOME/repository/logs/heap-dump.hprof" \
    $JAVA_OPTS \
    -Djava.util.logging.config.file="$CARBON_HOME/repository/conf/etc/logging-bridge.properties" \
    -DworkerNode=false \
    org.wso2.carbon.bootstrap.Bootstrap $*
    status=$?
done
</code></pre></div>

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

<p dir="auto">As can be seen, the lineinfile using a jinja template worked fine.  But the first insertafter  inserted quotes at the beginning and the end of my line.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="while [ &quot;$status&quot; = &quot;$START_EXIT_STATUS&quot; ]
do
    $JAVACMD \
    -Xbootclasspath/a:&quot;$CARBON_XBOOTCLASSPATH&quot; \
    $JVM_MEM_OPTS \
    -XX:+HeapDumpOnOutOfMemoryError \
    -XX:HeapDumpPath=&quot;$CARBON_HOME/repository/logs/heap-dump.hprof&quot; \
    $JAVA_OPTS \
    -Djava.util.logging.config.file=&quot;$CARBON_HOME/repository/conf/etc/logging-bridge.properties&quot; \
    -Djava.util.prefs.userRoot=&quot;/home/wso2/.java/.userPrefsJijJa&quot; \
&quot;    -Djava.util.prefs.userRoot=&quot;/home/wso2/.java/.userPrefs&quot; \&quot;
    -DworkerNode=false \
    org.wso2.carbon.bootstrap.Bootstrap $*
    status=$?
done
"><pre class="notranslate"><code class="notranslate">while [ "$status" = "$START_EXIT_STATUS" ]
do
    $JAVACMD \
    -Xbootclasspath/a:"$CARBON_XBOOTCLASSPATH" \
    $JVM_MEM_OPTS \
    -XX:+HeapDumpOnOutOfMemoryError \
    -XX:HeapDumpPath="$CARBON_HOME/repository/logs/heap-dump.hprof" \
    $JAVA_OPTS \
    -Djava.util.logging.config.file="$CARBON_HOME/repository/conf/etc/logging-bridge.properties" \
    -Djava.util.prefs.userRoot="/home/wso2/.java/.userPrefsJijJa" \
"    -Djava.util.prefs.userRoot="/home/wso2/.java/.userPrefs" \"
    -DworkerNode=false \
    org.wso2.carbon.bootstrap.Bootstrap $*
    status=$?
done

</code></pre></div>
<h5 dir="auto">ACTUAL RESULTS</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate">
</code></pre></div>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="172533941" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-core/issues/4499" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-core/issues/4499/hovercard" href="https://github.com/ansible/ansible-modules-core/issues/4499">ansible/ansible-modules-core#4499</a></p>