Ansible remote_user与ansible_user [英] Ansible remote_user vs ansible_user

查看:3016
本文介绍了Ansible remote_user与ansible_user的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题很简单:Ansible中的ansible_user(以前的ansible_ssh_user)和remote_user有什么区别,除了第一个是在配置文件中设置的,第二个是在角色/角色中设置的?它们与-u/--user命令行选项有何关系?

The question is simple: what is the difference between ansible_user (former ansible_ssh_user) and remote_user in Ansible, besides that the first one is set if configuration file and the latter one is set in plays / roles? How do they relate to -u / --user command line options?

推荐答案

它们似乎是相同的.在这里看看:

They both seem to be the same. Take a look here:

https://github.com. com/ansible/ansible/blob/c600ab81ee/lib/ansible/playbook/play_context.py#L46-L55

# the magic variable mapping dictionary below is used to translate
# host/inventory variables to fields in the PlayContext
# object. The dictionary values are tuples, to account for aliases
# in variable names.

MAGIC_VARIABLE_MAPPING = dict(
   connection       = ('ansible_connection',),
   remote_addr      = ('ansible_ssh_host', 'ansible_host'),
   remote_user      = ('ansible_ssh_user', 'ansible_user'),
   port             = ('ansible_ssh_port', 'ansible_port'),

此外,当我们要在ansible主机文件中指定默认SSH用户时使用ansible_user,在 playbook 上下文中使用remote_user.

Besides, ansible_user is used when we want to specifiy default SSH user in ansible hosts file where as remote_user is used in playbook context.

来自 https://github.com/ansible/ansible/blob/c600ab81ee/docsite/rst/intro_inventory.rst

ansible_user 要使用的默认ssh用户名.

ansible_user The default ssh user name to use.

,这是在ansible hosts文件中使用ansible_user的示例:

and here is an example of using ansible_user in ansible hosts file:

[targets]

localhost              ansible_connection=local
other1.example.com     ansible_connection=ssh        ansible_user=mpdehaan
other2.example.com     ansible_connection=ssh        ansible_user=mdehaan

这篇关于Ansible remote_user与ansible_user的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆