建立不同用户组的清单

问题描述 投票:0回答:0

我有几个云,每个云都有一个不同的用户,我们需要登录才能成为 root(用于安装服务)

现在,我们第一次收到新服务器时——我们以 root 身份登录,定义我们的服务帐户——然后所有 playbook 从此时开始都使用服务帐户登录以运行任务。

问题是 - “以 root 身份登录”的第一部分。基本上每组服务器都使用不同的东西,例如:

  1. 其中一台云服务器直接使用
    root@myserver
    登录
  2. Other servers cloud are using an
    admin@myserver
    to login then we need to say
    become: yes

我们在上述案例中的库存是这样的:

[myserver_cloud1]
# server that requires an admin user and from there to become root
x.x.x.x ansible_user=admin ansible_become=yes

[myserver_cloud2]
# root is by default in the playbook i just say become: yes
z.z.z.z

剧本然后有一个问题 -

ansible_user
将始终覆盖剧本中使用的任何
remote_user: {{service_account}}

所以我想做一些不同的事情,库存总是会说

ansible_user=my_service_account
但是我如何根据云类型在剧本中区分“如何”以root身份登录(直接,或通过管理员用户然后sudo)?

所以我不确定配置库存/剧本的正确方法是什么:

  1. 有时运行剧本为
    root
  2. 默认情况下运行剧本作为我的
    service account

任何想法?我想避免在命令行中说

-u

ansible ansible-inventory
© www.soinside.com 2019 - 2024. All rights reserved.