0

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?

3
  • @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) Commented Feb 12, 2018 at 15:33
  • 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} Commented Feb 12, 2018 at 15:36
  • stackoverflow.com/help/mcve Commented Feb 12, 2018 at 15:37

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.