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

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

<p dir="auto">Inventory</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.3.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/rteague/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Jan 17 2018, 14:28:32) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]"><pre class="notranslate"><code class="notranslate">ansible 2.4.3.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/rteague/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Jan 17 2018, 14:28:32) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]
</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

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

<p dir="auto">N/A</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">Inventory variables are treated differently depending on where they are defined.  If a variable is provided on the host line in an ini-style inventory, Ansible will perform automatic type conversion.  The same does not apply for variables defined in a vars group.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>


<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# test-inv
[masters]
localhost host_line_defined=&quot;{'host-type': 'master', 'sub-host-type': 'default', 'region': 'infra'}&quot;

[masters:vars]
vars_group_defined=&quot;{'host-type': 'master', 'sub-host-type': 'default', 'region': 'infra'}&quot;"><pre class="notranslate"><code class="notranslate"># test-inv
[masters]
localhost host_line_defined="{'host-type': 'master', 'sub-host-type': 'default', 'region': 'infra'}"

[masters:vars]
vars_group_defined="{'host-type': 'master', 'sub-host-type': 'default', 'region': 'infra'}"
</code></pre></div>

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

<p dir="auto">It is expected that variables are treated the same regardless of where they are defined in the inventory.  This can cause issues when users define variables for hosts in different ways which result in unexpected behavior in playbooks.</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">The variable <code class="notranslate">host_line_defined</code> is converted to a <code class="notranslate">dict</code>.<br>
The variable <code class="notranslate">vars_group_defined</code> remains a <code class="notranslate">string</code>.</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ ansible-inventory -i inventory/test-inv --list --yaml
all:
  children:
    masters:
      hosts:
        localhost:
          host_line_defined:
            host-type: master
            region: infra
            sub-host-type: default
          vars_group_defined: '{''host-type'': ''master'', ''sub-host-type'': ''default'',
            ''region'': ''infra''}'
    ungrouped: {}"><pre class="notranslate"><code class="notranslate">$ ansible-inventory -i inventory/test-inv --list --yaml
all:
  children:
    masters:
      hosts:
        localhost:
          host_line_defined:
            host-type: master
            region: infra
            sub-host-type: default
          vars_group_defined: '{''host-type'': ''master'', ''sub-host-type'': ''default'',
            ''region'': ''infra''}'
    ungrouped: {}
</code></pre></div>
<h5 dir="auto">Issue Type:</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">Ansible Version:</h5>
<p dir="auto">1.7</p>
<h5 dir="auto">Environment:</h5>
<p dir="auto">Vagrant machine with image "hashicorp/precise64".<br>
Ubuntu 12.04 LTS</p>
<h5 dir="auto">Summary:</h5>
<p dir="auto">I understand that this sounds really weird, but I can't find the source of the problem atm.<br>
When I run mailcatcher task and ini_file command executed <code class="notranslate">extension=redis.so</code> line is stripped out. Seems like easter-egg %)</p>
<h5 dir="auto">Steps To Reproduce:</h5>
<p dir="auto">I am running vagrant machine and configuring it with simple playbook. I am able to reproduce this issue with following data.<br>
ansible.cfg</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[defaults]
host_key_checking=false"><pre class="notranslate"><code class="notranslate">[defaults]
host_key_checking=false
</code></pre></div>
<p dir="auto">ansible_hosts</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="vagrantbox ansible_connection=local"><pre class="notranslate"><code class="notranslate">vagrantbox ansible_connection=local
</code></pre></div>
<p dir="auto">group_vars/all</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
env: prod"><pre class="notranslate"><code class="notranslate">
---
env: prod
</code></pre></div>
<p dir="auto">host_vars/vagrantbox</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
env: dev
"><pre class="notranslate"><code class="notranslate">
---
env: dev

</code></pre></div>
<p dir="auto">playbook.yml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- hosts: vagrantbox
  remote_user: vagrant
  sudo: True
  roles:
     - php-fpm
     - { role: mailcatcher, when: env == &quot;dev&quot; }"><pre class="notranslate"><code class="notranslate">
---
- hosts: vagrantbox
  remote_user: vagrant
  sudo: True
  roles:
     - php-fpm
     - { role: mailcatcher, when: env == "dev" }
</code></pre></div>
<p dir="auto">roles/php-fpm/handler/main.yml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- name: restart php5-fpm
  service: name=php5-fpm state=restarted enabled=true
"><pre class="notranslate"><code class="notranslate">
---
- name: restart php5-fpm
  service: name=php5-fpm state=restarted enabled=true

</code></pre></div>
<p dir="auto">roles/php-fpm/tasks/main.yml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- name: Add php 5.4 repository
  apt_repository: repo='ppa:ondrej/php5-oldstable'
- name: Install php-fpm and deps
  apt: pkg={{ item }} state=present
  with_items:
    - php5-fpm
    - php5
    - php5-cli
    - php5-imagick
    - php5-gd
    - php5-mcrypt
    - php5-mysql
    - php-apc
    - php5-curl
    - php5-mhash
    - php-pear
    - php5-dev
- shell: pecl list | grep -ic lzf
  register: lzf_installed
  failed_when: false
  changed_when: false
- shell: pecl install lzf
  when: lzf_installed.stdout|int == 0
- shell: pecl list | grep -ic redis
  register: redis_installed
  failed_when: false
  changed_when: false
- shell: pecl install redis
  when: redis_installed.stdout|int == 0
- set_fact: &gt;
    {% if env == &quot;prod&quot; %}apc_stat=0{% else %}apc_stat=1{% endif %}
- template: src=customizations.ini.j2 dest=/etc/php5/mods-available/customizations.ini mode=0644
  notify:
    - restart php5-fpm
- name: set symlink for custmizations file
  file: src=/etc/php5/mods-available/customizations.ini dest=/etc/php5/{{item}}/conf.d/customizations.ini owner=root group=root state=link
  with_items:
  - cli
  - fpm
  notify:
    - restart php5-fpm"><pre class="notranslate"><code class="notranslate">
---
- name: Add php 5.4 repository
  apt_repository: repo='ppa:ondrej/php5-oldstable'
- name: Install php-fpm and deps
  apt: pkg={{ item }} state=present
  with_items:
    - php5-fpm
    - php5
    - php5-cli
    - php5-imagick
    - php5-gd
    - php5-mcrypt
    - php5-mysql
    - php-apc
    - php5-curl
    - php5-mhash
    - php-pear
    - php5-dev
- shell: pecl list | grep -ic lzf
  register: lzf_installed
  failed_when: false
  changed_when: false
- shell: pecl install lzf
  when: lzf_installed.stdout|int == 0
- shell: pecl list | grep -ic redis
  register: redis_installed
  failed_when: false
  changed_when: false
- shell: pecl install redis
  when: redis_installed.stdout|int == 0
- set_fact: &gt;
    {% if env == "prod" %}apc_stat=0{% else %}apc_stat=1{% endif %}
- template: src=customizations.ini.j2 dest=/etc/php5/mods-available/customizations.ini mode=0644
  notify:
    - restart php5-fpm
- name: set symlink for custmizations file
  file: src=/etc/php5/mods-available/customizations.ini dest=/etc/php5/{{item}}/conf.d/customizations.ini owner=root group=root state=link
  with_items:
  - cli
  - fpm
  notify:
    - restart php5-fpm
</code></pre></div>
<p dir="auto">roles/php-fpm/templates/customizations.ini.j2</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="; {{ ansible_managed }}
[extension]
extension=redis.so
extension=lzf.so

[Date]
date.timezone = Europe/Tallinn

[PHP]
memory_limit = 512M
expose_php = Off
session.save_handler = redis
session.save_path = &quot;tcp://127.0.0.1:6379?database=0&amp;timeout=120&quot;

[APC]
apc.enabled = &quot;1&quot;
apc.enable_cli=0
apc.stat = &quot;{{ apc_stat }}&quot;
apc.max_file_size = &quot;5M&quot;
apc.localcache = &quot;1&quot;
apc.localcache.size = &quot;512&quot;
apc.shm_segments = &quot;1&quot;
apc.ttl = &quot;3600&quot;
apc.user_ttl = &quot;7200&quot;
apc.gc_ttl = &quot;3600&quot;
apc.cache_by_default = &quot;1&quot;
apc.filters = &quot;&quot;
apc.write_lock = &quot;1&quot;
;apc.num_files_hint= &quot;0&quot;
;apc.user_entries_hint=&quot;0&quot;
apc.num_files_hint = 10000
apc.user_entries_hint = 10000
apc.shm_size = &quot;256M&quot;
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.include_once_override = &quot;0&quot;
apc.file_update_protection=&quot;2&quot;
apc.canonicalize = &quot;1&quot;
apc.report_autofilter=&quot;0&quot;
apc.stat_ctime=&quot;0&quot;"><pre class="notranslate"><code class="notranslate">; {{ ansible_managed }}
[extension]
extension=redis.so
extension=lzf.so

[Date]
date.timezone = Europe/Tallinn

[PHP]
memory_limit = 512M
expose_php = Off
session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379?database=0&amp;timeout=120"

[APC]
apc.enabled = "1"
apc.enable_cli=0
apc.stat = "{{ apc_stat }}"
apc.max_file_size = "5M"
apc.localcache = "1"
apc.localcache.size = "512"
apc.shm_segments = "1"
apc.ttl = "3600"
apc.user_ttl = "7200"
apc.gc_ttl = "3600"
apc.cache_by_default = "1"
apc.filters = ""
apc.write_lock = "1"
;apc.num_files_hint= "0"
;apc.user_entries_hint="0"
apc.num_files_hint = 10000
apc.user_entries_hint = 10000
apc.shm_size = "256M"
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.include_once_override = "0"
apc.file_update_protection="2"
apc.canonicalize = "1"
apc.report_autofilter="0"
apc.stat_ctime="0"
</code></pre></div>
<p dir="auto">roles/mailcatcher/tasks/main.yml</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
---
- name: Add rubygems stable repository with latest versions
  apt_repository: repo='ppa:skottler/ruby193-latest' state=absent
- name: install ruby and rubygems
  apt: pkg={{ item }} state=present
  with_items:
    - ruby
    - ruby1.9.3
    - rubygems
    - libsqlite3-dev
- file: src=/usr/bin/ruby1.9.3 dest=/etc/alternatives/ruby state=link
- file: src=/etc/alternatives/ruby dest=/usr/bin/ruby state=link
- file: src=/usr/bin/gem1.9.3 dest=/etc/alternatives/gem state=link
- file: src=/etc/alternatives/gem dest=/usr/bin/gem state=link
- name: install mailcatcher
  gem: name=mailcatcher user_install=no
- name: get path to mailcatcher
  command: which catchmail
  register: catchmail_path
# strips out comment and extension=redis.so
- ini_file: dest=/etc/php5/mods-available/customizations.ini section=&quot;mail function&quot; option=sendmail_path value=&quot;{{ catchmail_path.stdout}} -f sent.from@vagrant.box&quot;
- shell: ps aux | grep &quot;mailcatcher --ip=0.0.0.0&quot; | grep -v grep | grep -c mailcatcher
  register: mailcatcher_started
  failed_when: False"><pre class="notranslate"><code class="notranslate">
---
- name: Add rubygems stable repository with latest versions
  apt_repository: repo='ppa:skottler/ruby193-latest' state=absent
- name: install ruby and rubygems
  apt: pkg={{ item }} state=present
  with_items:
    - ruby
    - ruby1.9.3
    - rubygems
    - libsqlite3-dev
- file: src=/usr/bin/ruby1.9.3 dest=/etc/alternatives/ruby state=link
- file: src=/etc/alternatives/ruby dest=/usr/bin/ruby state=link
- file: src=/usr/bin/gem1.9.3 dest=/etc/alternatives/gem state=link
- file: src=/etc/alternatives/gem dest=/usr/bin/gem state=link
- name: install mailcatcher
  gem: name=mailcatcher user_install=no
- name: get path to mailcatcher
  command: which catchmail
  register: catchmail_path
# strips out comment and extension=redis.so
- ini_file: dest=/etc/php5/mods-available/customizations.ini section="mail function" option=sendmail_path value="{{ catchmail_path.stdout}} -f sent.from@vagrant.box"
- shell: ps aux | grep "mailcatcher --ip=0.0.0.0" | grep -v grep | grep -c mailcatcher
  register: mailcatcher_started
  failed_when: False
</code></pre></div>
<h5 dir="auto">Expected Results:</h5>
<p dir="auto">In 'dev' environment customizations.ini file contains extension=redis.so line as well as mail function config</p>
<h5 dir="auto">Actual Results:</h5>
<p dir="auto">In 'dev' environment customizations.ini file does not contain extension=redis.so line as well as ansible managed comment.</p>