ansible - ansible:以不同的用户身份运行角色
问题描述
我有两个角色在剧本中运行,一个创建用户,另一个运行一系列任务,我想在服务器上作为新创建的用户运行这些任务。
剧本是这样写的:
- 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
推荐阅读
- c - 如何在C中使用多个分隔符进行拆分
- java - 使用Java计算句子中单词的出现次数
- visual-studio-code - 为什么 Visual Studio 代码显示 p5 串行错误
- php - CountryTableSeeder 不存在 - Laravel
- path - 使用 Inspect Element 时如何从一行代码中找到源文件名或路径?
- javascript - Asp.net Server 代码执行两次,返回失败的回调方法
- python - 获取所需的字符串
- pyspark - Apache Spark - 编写带有快速压缩错误的镶木地板
- javascript - 不和谐音乐机器人跳跃功能
- sandbox - Ambari 服务器未在 Mac M1 上的端口 8080 上运行