Hi All,
The following playbook worked fine with Ansible 1.9.4, but is breaking in 2.0.0.2:
1.9.4 version:
---
- hosts:
- all
gather_facts: True
- name: Do local stuff
hosts: 127.0.0.1
connection: local
tasks:
- name: Add dev environment to hostsfile
sudo: true
lineinfile:
dest: "/etc/hosts"
regexp: "{{ item }}"
line: "{{ hostvars[item]['ansible_default_ipv4']['address'] }} {{ item }}"
with_items: groups.all
- name: Remove existing hostkey
shell: "ssh-keygen -R {{ item }}"
with_items: groups.all
- name: Add new host key
shell: "ssh-keyscan {{ item }} >> ~/.ssh/known_hosts"
with_items: groups.all
and this is the 2.0.0.2 version:
---
- hosts: all
gather_facts: True
tasks:
- name: setup
setup:
- name: Do local stuff
hosts: localhost
connection: local
tasks:
- name: Add dev environment to hostsfile
lineinfile:
dest: "/etc/hosts"
regexp: "{{ item }}"
line: "{{ hostvars[item]['ansible_default_ipv4']['address'] }} {{ item }}"
with_items: groups.all
become: true
delegate_to: localhost
- name: Remove existing hostkey
shell: "ssh-keygen -R {{ item }}"
with_items: groups.all
- name: Add new host key
shell: "ssh-keyscan {{ item }} >> ~/.ssh/known_hosts"
with_items: groups.all
But when we run this:
TASK [Add dev environment to hostsfile] ****************************************
task path: /home/mark/Documents/persgroep/provisioning/test/update_host_file.yml:13
ESTABLISH LOCAL CONNECTION FOR USER: mark
localhost EXEC ( umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1455181192.78-70674952507744 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1455181192.78-70674952507744 )" )
localhost PUT /tmp/tmpELrS4d TO /home/mark/.ansible/tmp/ansible-tmp-1455181192.78-70674952507744/lineinfile
localhost EXEC /bin/sh -c 'sudo -H -S -p "[sudo via ansible, key=afiilhlujllfoqvhmyqhfxivjsbaqdbp] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-afiilhlujllfoqvhmyqhfxivjsbaqdbp; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /home/mark/Envs/persgroep/bin/python /home/mark/.ansible/tmp/ansible-tmp-1455181192.78-70674952507744/lineinfile; rm -rf "/home/mark/.ansible/tmp/ansible-tmp-1455181192.78-70674952507744/" > /dev/null 2>&1'"'"''
localhost EXEC ( umask 22 && mkdir -p "$( echo $HOME/.ansible/tmp/ansible-tmp-1455181193.73-10161341089142 )" && echo "$( echo $HOME/.ansible/tmp/ansible-tmp-1455181193.73-10161341089142 )" )
localhost PUT /tmp/tmpF8fuw4 TO /home/mark/.ansible/tmp/ansible-tmp-1455181193.73-10161341089142/lineinfile
localhost EXEC /bin/sh -c 'sudo -H -S -p "[sudo via ansible, key=feteajroilmicneyttrpeownjlnwlkgd] password: " -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-feteajroilmicneyttrpeownjlnwlkgd; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /home/mark/Envs/persgroep/bin/python /home/mark/.ansible/tmp/ansible-tmp-1455181193.73-10161341089142/lineinfile; rm -rf "/home/mark/.ansible/tmp/ansible-tmp-1455181193.73-10161341089142/" > /dev/null 2>&1'"'"''
fatal: [localhost]: FAILED! => {"failed": true, "msg": "ERROR! privilege output closed while waiting for password prompt:\nBECOME-SUCCESS-feteajroilmicneyttrpeownjlnwlkgd\n{\"msg\": \"\", \"invocation\": {\"module_args\": {\"directory_mode\": null, \"force\": null, \"remote_src\": null, \"backrefs\": false, \"insertafter\": null, \"owner\": null, \"follow\": false, \"line\": \"172.17.0.156 test-percona-02\", \"group\": null, \"insertbefore\": null, \"create\": false, \"setype\": null, \"content\": null, \"serole\": null, \"state\": \"present\", \"dest\": \"/etc/hosts\", \"selevel\": null, \"regexp\": \"test-percona-02\", \"validate\": null, \"src\": null, \"seuser\": null, \"delimiter\": null, \"mode\": null, \"backup\": false}}, \"changed\": false, \"backup\": \"\"}\n"}
I was thinking that using connection: local
somehow interfered with become: true
But I installed openssh-server and tried it via normal ssh means and still didn’t work.
I tried things with become: root, delegate_to, changing things in inventory, nothing seems to work. I’d love any suggestion?
Thanks!
Mark