Issue 1:
ISSUE TYPE

Bug Report

COMPONENT NAME

lineinfile

ANSIBLE VERSION

ansible 2.3.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides

CONFIGURATION

[defaults]
log_path = ~/ansible/log/ansible.log
timeout = 1
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
error_on_undefined_vars = True

[ssh_connection]
pipelining = True

[accelerate]
accelerate_port = 5099
accelerate_timeout = 30
accelerate_connect_timeout = 1.0
accelerate_multi_key = yes

OS / ENVIRONMENT

Ubuntu 16.04.1 LTS

(last version from : https://github.com/ansible/ansible.git)

SUMMARY

When I use the lineinfile module, and when I use a variable in the line: parameter :

if the variables contains "all", rhe playbook fails with : "An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: is not JSON serializable

fatal: [localhost]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}"

STEPS TO REPRODUCE

command line : ansible-playbook ./test_bracket_lineinfile.yml --inventory=localhost

playbook : ./test_bracket_lineinfile.yml

---
- name: "Test"
hosts: localhost
pre_tasks:
- name: "Bug with 'all' as nextcons_ansible_group"
lineinfile:
path: "./test.txt"
line: "[{{nextcons_ansible_group}}]"
create: yes
state: present
delegate_to: 127.0.0.1
run_once: true
become: no
when: nextcons_ansible_group is defined and nextcons_ansible_group != ""
vars:
nextcons_ansible_group: 'all'
...

EXPECTED RESULTS

Working correctly, at when I replace 'all' by 'plop' as nextcons_ansible_group variable content :

ansible-playbook ./test_bracket_lineinfile.yml --inventory=localhost
[WARNING]: Host file not found: localhost

[WARNING]: provided hosts list is empty, only localhost is available

PLAY [Test] *************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Bug with 'all' as nextcons_ansible_group] *************************************************************************************************************************************************************
ok: [localhost -> 127.0.0.1]

PLAY RECAP **************************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0

ACTUAL RESULTS

The content 'all' in a variable that is used in the line: argument triggers an error.

Output :

ansible-playbook ./test_bracket_lineinfile.yml --inventory=localhost
[WARNING]: Host file not found: localhost

[WARNING]: provided hosts list is empty, only localhost is available

PLAY [Test] *************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Bug with 'all' as nextcons_ansible_group] *************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TypeError: <built-in function all> is not JSON serializable
fatal: [localhost]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}

NO MORE HOSTS LEFT ******************************************************************************************************************************************************************************************
to retry, use: --limit @/home/ghusson/ownCloud/2014_entreprise_ssii/infra_informatique/99_ansible_dev/test_playbooks/test_bracket_lineinfile.retry

PLAY RECAP **************************************************************************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1

Issue 2:
The question comes up how to distribute SSH keys to different users.

In this case, suppose we have:

users:

- name: xyz

ssh_keys: [ /path/to/x, y, z ]

- name: abc

ssh_keys: [ xx, yy ]

We might want to use the authorized_key module in a with_items loop, so it would be nice to say:

with_subelements:
- users:
- 'ssh_keys'

And in this invocation, it would return {{ item.0 }} as each record, and {{ item.1 }} as each subelement of the given field name, as such:

authorized_key: name={{ item.0.name }} key={{ lookup('file', item[1]) }}

with_subelements:

- users

- 'ssh_keys'

Alternative proposals welcome.

Having a sufficient number of lookup plugins for the 'odd' cases.