Ashok Reddy
Ashok Reddy

Reputation: 1085

ansible playbook is connecting with admin user by default

when i run ansible playbook, by defult it's trying to connect remote servers with admin user, not considering user in play book

root@c63fe05c2307:/# ansible-playbook play.yml

PLAY [all] *********************************************************************

TASK [shell] *******************************************************************
fatal: [172.17.0.3]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: [email protected]: Permission denied (publickey,password).\r\n", "unreachable": true}
        to retry, use: --limit @/play.retry

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

actually i mention remote user as sdnask user below is my playbook

---
- hosts: all
  gather_facts: false
  remote_user: sdnask
  become: yes
  become_method: sudo

  tasks:
  - shell: mkdir /test2 

whatever user i mentioned in playbook no matter, but it's trying to connect through admin user , even if i am trying to run ansible all -u sdnask -m ping it's trying to connect with admin user. can anyone please suggest what causing issue?

Upvotes: 0

Views: 991

Answers (1)

Vladimir Botka
Vladimir Botka

Reputation: 68144

Try ansible_user to ssh connect.

ansible_user: sdnask

You might want to run the playbook below to find where does the admin come from.

- hosts: 172.17.0.3
  tasks:
    - name: List all vars
      vars: 
        msg: |
        Module Variables ("vars"):
        --------------------------------
        {{ vars | to_nice_json }}

        Environment Variables ("environment"):
        --------------------------------
        {{ environment | to_nice_json }}

        GROUP NAMES Variables ("group_names"):
        --------------------------------
        {{ group_names | to_nice_json }}

        GROUPS Variables ("groups"):
        --------------------------------
        {{ groups | to_nice_json }}

        HOST Variables ("hostvars"):
        --------------------------------
        {{ hostvars | to_nice_json }} 

      debug:
        msg: "{{ msg.split('\n') }}"

Upvotes: 1

Related Questions