ansible: 运行 作为不同用户的角色
ansible: run role as a different user
我在剧本中有两个 运行 角色,一个创建用户,另一个 运行 通过一系列我想 运行 作为服务器上新创建的用户。
剧本是这样写的:
- hosts: centos
connection: ssh
gather_facts: false
become: true
roles:
- ../roles/user_setup
- ../roles/tasks
假设从 user_setup
角色创建的用户名为 user1
:我基本上想要名为 tasks
到 运行 的角色为 user1
。最好的方法是什么?谢谢。
几乎给你提供了一个解决方案。您可以使用类似的东西:
- hosts: centos
connection: ssh
gather_facts: false
roles:
- role: ../roles/user_setup
become: true
- role: ../roles/tasks
become: true
become_user: user1
如果您想直接连接为 user1
(而不是升级到它),您可以将最新的角色调用替换为:
- role: ../roles/tasks
become: false
remote_user: user1
我在剧本中有两个 运行 角色,一个创建用户,另一个 运行 通过一系列我想 运行 作为服务器上新创建的用户。
剧本是这样写的:
- hosts: centos
connection: ssh
gather_facts: false
become: true
roles:
- ../roles/user_setup
- ../roles/tasks
假设从 user_setup
角色创建的用户名为 user1
:我基本上想要名为 tasks
到 运行 的角色为 user1
。最好的方法是什么?谢谢。
- hosts: centos
connection: ssh
gather_facts: false
roles:
- role: ../roles/user_setup
become: true
- role: ../roles/tasks
become: true
become_user: user1
如果您想直接连接为 user1
(而不是升级到它),您可以将最新的角色调用替换为:
- role: ../roles/tasks
become: false
remote_user: user1