问题很简单:Ansible 中的 ansible_user
(以前的 ansible_ssh_user
)和 remote_user
有什么区别,除了第一个是设置是否配置文件并且后一个设置在plays/roles中?它们与 -u
/--user
命令行选项有何关系?
最佳答案
它们似乎都是一样的。
看这里:
# 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'),
来源:https://github.com/ansible/ansible/blob/c600ab81ee/lib/ansible/playbook/play_context.py#L46-L55
此外,当我们想要在ansible主机文件中指定默认SSH用户时,会使用ansible_user
,而remote_user
用于剧本上下文。
来自https://github.com/ansible/ansible/blob/c600ab81ee/docsite/rst/intro_inventory.rst
ansible_user The default ssh user name to use.
这是在 ansiblehosts
文件中使用 ansible_user
的示例:
[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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36668756/