Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

Inventory

ANSIBLE VERSION

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)]

CONFIGURATION

Default

OS / ENVIRONMENT

N/A

SUMMARY

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.

STEPS TO REPRODUCE

# 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'}"

EXPECTED RESULTS

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.

ACTUAL RESULTS

The variable host_line_defined is converted to a dict.

The variable vars_group_defined remains a string.

$ 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: {}

Issue 2:
Issue Type:

Bug Report

Ansible Version:

1.7

Environment:

Vagrant machine with image "hashicorp/precise64".

Ubuntu 12.04 LTS

Summary:

I understand that this sounds really weird, but I can't find the source of the problem atm.

When I run mailcatcher task and ini_file command executed extension=redis.so line is stripped out. Seems like easter-egg %)

Steps To Reproduce:

I am running vagrant machine and configuring it with simple playbook. I am able to reproduce this issue with following data.

ansible.cfg

[defaults]
host_key_checking=false

ansible_hosts

vagrantbox ansible_connection=local

group_vars/all

---
env: prod

host_vars/vagrantbox

---
env: dev

playbook.yml

---
- hosts: vagrantbox
remote_user: vagrant
sudo: True
roles:
- php-fpm
- { role: mailcatcher, when: env == "dev" }

roles/php-fpm/handler/main.yml

---
- name: restart php5-fpm
service: name=php5-fpm state=restarted enabled=true

roles/php-fpm/tasks/main.yml

---
- 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: >
{% 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

roles/php-fpm/templates/customizations.ini.j2

; {{ 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&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"

roles/mailcatcher/tasks/main.yml

---
- 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

Expected Results:

In 'dev' environment customizations.ini file contains extension=redis.so line as well as mail function config

Actual Results:

In 'dev' environment customizations.ini file does not contain extension=redis.so line as well as ansible managed comment.