0
votes

We currently have 3 boxes setup via Vagrant, with the following inventory file:

[loadbalancer]
node-1 ansible_host=192.168.50.10 ansible_user=ubuntu

[webservers]
node-2 ansible_host=192.168.50.11 ansible_user=ubuntu

[dbservers]
node-3 ansible_host=192.168.50.12 ansible_user=ubuntu

I'm following the github example for a rolling upgrade: https://github.com/ansible/ansible-examples/blob/master/lamp_haproxy/rolling_update.yml

My playbook looks like this:

pre_tasks:
- name: disable the server in haproxy
  haproxy: 'state=disabled backend=myapplb host={{ inventory_hostname }} socket=/var/lib/haproxy/stats'
  delegate_to: "{{ ansible_host }}"
  with_items: groups.loadbalancer

The task fails with the below statement:

failed: [node-2] (item=groups.loadbalancer) => {"item": "groups.loadbalancer", "msg": "Failed to connect to the host via ssh: [email protected]: Permission denied (publickey).\r\n", "unreachable": true}

What is surprising is the line XXX@192.168.50.11. XXX does not match the ansible_user provided in the inventory file.

Could this be the cause of the error?

1
@techraf: I understand the message. A slow way of dealing with it is to clean my known_hosts everytime I re-provision the boxes. By adding the host_key_checking = False directive in the ansible.cfg, this error does not occur on all the other tasks. It only fails when using the delegate_to. Furthermore, it seems that Ansible is trying to connect with the user XXX instead of ubuntu (as per the inventory file)E. Jaep
I just cleaned the known_hosts file and now gets the error message: > failed: [node-2] (item=groups.loadbalancer) => {"item": "groups.loadbalancer", "msg": "Failed to connect to the host via ssh: [email protected]: Permission denied (publickey).\r\n", "unreachable": true}E. Jaep

1 Answers

3
votes

Just found that I should add the remote_user parameter to the task. The correct syntax is:

pre_tasks:
- name: disable the server in haproxy
  haproxy: 'state=disabled backend=myapplb host={{ inventory_hostname }} socket=/var/lib/haproxy/stats'
  delegate_to: "{{ ansible_host }}"
  remote_user: "{{ ansible_user }}"
  with_items: groups.loadbalancer