2017-02-23 37 views
0

I'm新手与这个梦幻般的自动化引擎,并具备与瓦尔文件有点问题:ANSIBLE:使用一个主机文件变量(SSH)

由momment,我必须使用通过SSH连接不keypars一个特定的用户和密码。

hosts文件

[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 

我也想包有 “”,{},但没有作品。

如何在此参数上使用变量?

+0

为什么不直接定义'ansible_connection'等PARAMS在'[所有:瓦尔]'? –

回答

2

ansible_ssh_user自2.0版以来已被弃用。它变成ansible_user。见here

千万不要以纯文本形式存储ansible_ssh_pass变量;总是使用保险库。见Variables and Vaults

无论如何,具有mytest.inventory文件如下

[all:vars] 
ssh_user1=user1 

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

它的工作原理,例如

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

选项-k要求输入密码。

如果你还是要写清单中的密码,您可以让密码变量定义,并添加ansible_ssh_pass="{{ ssh_pass1 }}"

[serverstest] 
192.168.15.201 ansible_user="{{ ssh_user1 }}" ansible_ssh_pass="{{ ssh_pass1 }}" 
+0

谢谢!我只是在实验室环境中测试可能性来实现这个解决方案。通过momment,安全已经没有很高的优先级,但你的约会感激地接受了:) 进出口检验以下 '[所有:瓦尔] ssh_user1 =用户 ssh_pass1 =密码 [serverstest] MACHINE1 ansible_ssh_user =” {{ssh_user1}}” ansible_ssh_pass = “{{ssh_pass1}}” 机2 ansible_user = “{{ssh_user1}}” ansible_ssh_pass = “{{ssh_pass1}}”' – Ramos

+0

右评论: 林测试以下 '[all:vars] ssh_user1 =用户 ssh_pass1 =密码 [serverstest] MACHINE1 ansible_ssh_user = “{{ssh_user1}}” ansible_ssh_pass = “{{ssh_pass1}}” 机2 ansible_user =“{{ssh_user1}} “ansible_ssh_pass =”{{ssh_pass1}}“' 机器2(用户没有”ssh“)不起作用。但它并不重要 非常感谢您的反馈 – Ramos

+0

可能会依赖于Ansible版本。如果它小于2.0,anslibe_ssh_user是正确的。 – gile

相关问题