mad*_*ead 26 ansible ansible-playbook ansible-2.x
问题很简单:(ansible_user前ansible_ssh_user)和remote_userAnsible 之间的区别是什么,除了第一个是设置文件而后者设置为播放/角色?它们如何与-u/ --user命令行选项相关?
sla*_*fer 32
它们似乎都是一样的.看看这里:
https://github.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'),
Run Code Online (Sandbox Code Playgroud)
此外,ansible_user当我们想在ansible hosts文件中指定默认SSH用户时remote_user使用,其中在playbook上下文中使用.
来自https://github.com/ansible/ansible/blob/c600ab81ee/docsite/rst/intro_inventory.rst
ansible_user要使用的默认ssh用户名.
这是一个ansible_user在ansible hosts文件中使用的例子:
[targets]
localhost ansible_connection=local
other1.example.com ansible_connection=ssh ansible_user=mpdehaan
other2.example.com ansible_connection=ssh ansible_user=mdehaan
Run Code Online (Sandbox Code Playgroud)
小智 5
remote_user 和 ansible_user 之间的一个区别:
当您使用剧本中的不同用户运行角色时,例如:
- name: Apply user configuration to user root
hosts: all
remote_user: root
- name: Apply user configuration to user murphy
hosts: all
remote_user: murphy
Run Code Online (Sandbox Code Playgroud)
然后,您可以使用“when: ansible_user == ..”而不是“when: remote_user == ..”为不同的用户执行条件任务。例如:
- name: Add user murphy to wheel group
user:
name: murphy
groups: wheel
append: yes
when: ansible_user == "root"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31824 次 |
| 最近记录: |