2

I´m newbie with this fantastic automation engine, and have a little issue with the vars file:

By the momment, I must connect via SSH without keypars using an specifics users and password.

hosts file

[all:vars]
connection_mode1=ssh 
ssh_user1=user1
ssh_pass1=pass1

[serverstest]
host1 ansible_connection=connection_mode1 ansible_ssh_user=ssh_user1 ansible_ssh_pass=ssh_pass1

I'm also trying wrap with "" and {} but doesn't works.

How can I use variables on this parameters?

1
  • why not just define ansible_connection and other params in [all:vars]? Commented Feb 23, 2017 at 9:23

1 Answer 1

4

ansible_ssh_user has been deprecated since v. 2.0. It becomes ansible_user. See here.

Never store ansible_ssh_pass variable in plain text; always use a vault. See Variables and Vaults.

Anyway, having a mytest.inventory file as follows

[all:vars]
ssh_user1=user1

[serverstest]
host1 ansible_user="{{ ssh_user1 }}"

it works, e.g.

ansible -i mytest.inventory serverstest -m ping -k

Option -k asks for the password.

If you still want to write the password in the inventory you can leave the password variable definition and add ansible_ssh_pass="{{ ssh_pass1 }}"

[serverstest]
192.168.15.201 ansible_user="{{ ssh_user1 }}" ansible_ssh_pass="{{ ssh_pass1 }}"
Sign up to request clarification or add additional context in comments.

3 Comments

thank you! I´m only testing the possibilities in a lab´environment to implement this solutions. By the momment, the security has not a high priority but your appointment is gratefully accepted :) Im test the following [all:vars] ssh_user1=user ssh_pass1=password [serverstest] machine1 ansible_ssh_user="{{ ssh_user1 }}" ansible_ssh_pass="{{ ssh_pass1 }}" machine2 ansible_user="{{ ssh_user1 }}" ansible_ssh_pass="{{ ssh_pass1 }}"
Right comment: Im test the following [all:vars] ssh_user1=user ssh_pass1=password [serverstest] machine1 ansible_ssh_user="{{ ssh_user1 }}" ansible_ssh_pass="{{ ssh_pass1 }}" machine2 ansible_user="{{ ssh_user1 }}" ansible_ssh_pass="{{ ssh_pass1 }}" the machine 2 (without "ssh" in the user) not works. But it doesn´t matter Thank you so much for your feedback
May be it depends from the Ansible version. If it is less than 2.0 anslibe_ssh_user is right.

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.