gpt4 book ai didi

Ansible Remote_user 与 ansible_user

转载 作者:行者123 更新时间:2023-12-02 06:53:46 32 4
gpt4 key购买 nike

问题很简单: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_userThe 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com