Ansible Remote_user 与 ansible_user

标签 ansible ansible-2.x

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

相关文章:

ansible - Ansible-检查文件中是否存在字符串

amazon-ec2 - 如何使用 Ansible ec2_vpc_route_table 将路由添加到 VPC 的默认/主路由表?

linux - 从 Ansible Playbook 创建用户密码

linux - 如何在 Ansible 中创建没有 .bashrc 的用户?

Ansible 在 stdout 输出中搜索子字符串

python - 努力在Python脚本中传递ansible变量

ansible - 如何使用Ansible wait_for检查多行命令状态?

ansible - 在 playbook 中运行任务之前,如何设置确认提示?

ansible - 我可以指定参数不能与 Ansible 模块规范中的特定选项一起使用吗?

amazon-ec2 - Ansible ec2_remote_facts