【发布时间】:2018-02-15 17:06:06
【问题描述】:
我目前正在一个安装了 ansible 的主机上工作。我创建了 2 个应用程序帐户,其中包含 nologin 组,并且我想在该组中添加用户,以便每个部门都有自己的 ansible 目录。
我的变量如下所示:
---
- hosts: localhost
become: yes
vars:
ansible_groupuser:
- name: "ansible-dictators"
ansible_groupuser_uid: "3000"
ansible_users:
- idia
- josefs
- donaldt
- kimjongu
- name: "ansible-druglords"
ansible_groupuser_uid: "3001"
ansible_users:
- pabloe
- javierg
- frankl
- rossu
现在我有两部戏。 1 创建Groupuser:
# This creates the groupuser
- name: Play 1 Create central ansible user and group per department
user:
name: "{{ item.name }}"
shell: "/sbin/nologin"
home: "/home/{{ item.name }}"
comment: "{{ item.name }} Group Account"
uid: "{{ item.ansible_groupuser_uid }}"
append: "yes"
with_items:
- "{{ansible_groupuser}}"
和 1 创建“普通”用户:
- name: Play 2 Create users
user:
name: "{{ item.1 }}"
shell: "/bin/bash"
home: "/home/{{ item.1 }}"
comment: "{{ item.1 }}"
groups: "{{ item.0.name }}"
append: "yes"
with_subelements:
- "{{ ansible_groupuser }}"
- ansible_users
如果我运行这个游戏,它会在 3000 上创建组用户 ansible-dictators,在 3001 上创建 ansible-druglords。idia 获得 3002,josefs 获得 3003 等等。当我想添加第三个组用户时,它有点混乱,比如 ansible-rockstars ,它从第一个可用的 uid 3010 开始计数。我想要将 groupusers 和 common 用户放在 2 个不同的范围内(例如 2000 和 3000)
当我在第一场比赛中使用 with_together 时,如下所示:
- name: Play1 Create central ansible user and group per department
user:
name: "{{ item.0.name }}"
shell: "/sbin/nologin"
home: "/home/{{ item.0.name }}"
comment: "{{ item.0.name }} Group Account"
uid: "{{ item.1 }}"
append: "yes"
with_together:
- "{{ansible_groupuser}}"
- "{{ range(3000,3020)|list }}"
when: item.0 != None
但是当我在第二场比赛中使用 with_together 时,它不起作用:
- name: Create users
user:
name: "{{ item.1 }}"
shell: "/bin/bash"
home: "/home/{{ item.1 }}"
comment: "{{ item.1 }}"
groups: "{{ item.0.name }}"
append: "yes"
uid: "{{ item.2 }}"
with_together:
- "{{ ansible_groupuser }}"
- ansible_users
- "{{ range(2000,2020)|list }}"
有人建议如何使用特定范围内的 uid 使第二个游戏工作?或者另一个建议如何在不同的组中获取 uid?在 vars 中给 groupusers 一个 uid 是没有问题的。但我希望添加很多“普通”用户(+50),我不想为所有这些用户指定一个 uid。
希望这是有道理的。提前致谢。
【问题讨论】:
标签: ansible user-roles uid