The connection variable defined at the command line have a lower priority that the connection variables defined elsewehere (such as playbook,…).See Playbook Variable
Example:
---
- hosts: all
remote_user: ramon # connection user must be ramon
ansible -u lola myhost
A connection_variable can be:
ansible-playbook playbook.yml -i inventory.ini --extra-vars "ansible_sudo_pass=yourPassword"
There is no option to store passphrase-protected private key. See the note in List of Behavioral Inventory Parameters.
You need to:
https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html#non-ssh-connection-types
Make sure you have ran ConfigureRemotingForAnsible.ps1 on your windows host
See ansible/ansible/tree/devel/lib/ansible/plugins/connection
You can define the running user with the help of this two variable:
If the ansible_user is defined in a inventory file, the remote_user value will have no effect because of order of precedence. You need to become instead. See 20045
Example:
hostName ansible_host=13.72.199.20 ansible_ssh_pass=Gam5sKZ8g6Q ansible_become_pass=GuCZWuGam5sKZ8g6Q
---
- hosts: all
become: yes
become_user: install_user
---
- hosts: all
remote_user: login_user
become: yes
become_user: install_user
ansible-playbook playbook.yml -i hosts.ini
Ansible get the privaye key: