Create a new group x and users a and b on the target server (192.168.100.251) using Ansible,
I want to attach a and b to x, but I get an error. The OS is CentOS7 for both Ansible operation terminal and target server.
/tmp/group_vars/users.ymluser_groups:
'-{name:' x ', gid: 100}
/tmp/setup.ymlusers:
'-{name:' a ', uid: 123, group:' x '}
'-{name:' b ', uid: 124, group:' x '}
/tmp/roles/useradd/task/create_user_group.yml-hosts: 192.168.100.251
remote_user: root
become: true
roles:
'-setup
vars_files:
'-group_vars/user_groups.yml
'-group_vars/users.yml
Execution result'-hosts: 192.168.100.251
remote_user: root
become: true
tasks:
'-name: create group
group:
name: "{{item.name}}"
gid: "{{item.gid}}"
state: present
with_items:
'-"{{user_groups}}"'-name: create user
user:
name: "{{item.name}}"
uid: "{{item.uid}}"
groups: "{{item.group}}"
with_items:
'-"{{users}}"
[root @ HOGE tmp] # ansible-playbook /tmp/roles/useradd/task/create_user_group.yml
PLAY [192.168.100.251]****************************************************** ************************************************** ********************
TASK [Gathering Facts]************************************************** ************************************************** ********************
Enter passphrase for key '/root/.ssh/id_rsa':
ok: [192.168.100.251]
TASK [create group]************************************************** ************************************************** ***********************
fatal: [192.168.100.251]: FAILED! =>{"msg": "'user_groups' is undefined"}
to retry, use: --limit @/tmp/roles/useradd/task/create_user_group.retry
PLAY RECAP****************************************************** ************************************************** ********************************
192.168.100.251: ok = 1 changed = 0 unreachable = 0 failed = 1
I fixed it.
I would appreciate it if you could teach me. Thank you.
-
Answer # 1
-
Answer # 2
There may be a problem with the code indentation, so could you please correct the above code in Markdown format?
The values of groups in the user module must be an array, please check.
Related articles
- mysql - i want to create a db user for multiple servers with ansible
- centos - ansible (v27) about referencing multiple arrays
- python - i want to create multiple windows and display images at the same time with tkinter
- c # - i want to create an npc that tracks multiple players by switching targets
- i do not know how to automatically create the specified directory when creating a new user with centos7
- use ansible with centos8 to build a proxy
- i want to create a combination of multiple arrays with numpy
- NodeJS multiple ways to create WebSocket monitoring (three kinds)
- centos - unable to create directory with filezilla
- centos - registration to dns server (local) when multiple hosts are attached to the same ip
- centos - install rpm package with ansible
- ruby - i want to create multiple radio buttons in form_tag with rails
- Easy language "does it support multiple users" command
- i want to create a centos + nginx + laravel + mysql environment on a mac
- i want to create an email with multiple files attached using vba
- angular2 - how to create multiple same component
- javascript - create multiple squares using dom
- centos - is it possible to open multiple tabs in virtualbox?
- google apps script - i want to create multiple branches in google form
- linux : To connect to a host that automatically performs an interactive installation when connecting with Ansible
- centos - freezes around sshpass related to ansible public key authentication
- use ansible with centos8 to build a proxy
- centos - install rpm package with ansible
- centos - ansible (v27) about referencing multiple arrays
- centos - i want to use [variable] template files using ansible
- how to install oracle jdk 8 with ansible
- python - when i run ansible-playbook, there is no particular error, but nothing happens on the client side
- Sample code for installing Ansible under Centos
How do you load addgroup.yml and adduser.yml?