【发布时间】:2020-06-13 10:37:30
【问题描述】:
我正在尝试使用 Ansible playbook 创建新用户和组。下面是我的文件夹结构。
tree
.
├── create-users.yaml
└── ubuntu
create-users.yaml playbook 包含创建用户和组任务。请注意,我的目标计算机中没有任何组 (admin_group) 和用户 (Rajini, Kamal),而是在运行 playbook 时创建它们。
---
- name: Create Users & Groups
hosts: target1
gather_facts: false
tasks:
- name: Create Users Task
user:
name: "{{ item }}"
state: present
password: "{{ 'default_user_password' | password_hash('sha512','A512') }}"
shell: /bin/bash
groups: "{{ admin_group }}"
loop:
- Rajini
- Kamal
我有另一个名为ubuntu 的文件来选择组名和密码。运行 playbook 时出现以下错误。
ansible-playbook --vault-id @prompt create-users.yaml -K
BECOME password:
Vault password (default):
PLAY [Create Users & Groups] *****************************************************************************************************************************************************************
TASK [Create Users Task] *********************************************************************************************************************************************************************
fatal: [target1]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'admin_group' is undefined\n\nThe error appears to be in '/home/osboxes/Ansible_Project/web_deployment/Ansible/groups_vars/create-users.yaml': line 6, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Create Users Task\n ^ here\n"}
PLAY RECAP ***********************************************************************************************************************************************************************************
target1 : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
admin_group: admin
default_user_password: Password1
有人可以帮我解决这个问题吗?
在得到用户 Moon 的帮助后更新输出。
ansible-playbook --vault-id @prompt create-users.yaml -K
BECOME password:
Vault password (default):
PLAY [Create Users & Groups] *****************************************************************************************************************************************************************
TASK [Create Users Task] *********************************************************************************************************************************************************************
changed: [target1] => (item=Rajini)
changed: [target1] => (item=Kamal)
PLAY RECAP ***********************************************************************************************************************************************************************************
target1 : ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ssh Kamal@192.168.0.1
Kamal@192.168.0.1's password:
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 5.0.0-23-generic x86_64)
Kamal@Ansible_Target1:~$ id
uid=1005(Kamal) gid=1001(admin) groups=1001(admin)
【问题讨论】:
标签: ansible