ansible使用vars_prompt交互变量,user,group模块增加账号密码 |
发表者:admin分类:Devops2020-05-21 11:04:49 阅读[1472] |
1,var_prompt 提示用户输入信息,然后将用户输入的信息存入到指定的变量中,
---
- name: 92cto hosts add New group and user.
hosts: micoder.cc
user: root
gather_facts: false
vars_prompt:
- name: "groups_name"
prompt: "input New groups_name"
- name: "user_name"
prompt: "input New USER_NAME"
private: no
- name: "user_passwd"
prompt: "Enter Password"
encrypt: "sha512_crypt"
confirm: yes
tasks:
- name: create New group.
group:
name: "{{ groups_name }}"
state: present # not required. choices: absent;present. Whether the group should be present or not on the remote host.
gid: 1008 # not required. Optional I(GID) to set for the group.
local: no # not required. Forces the use of "local" command alternatives on platforms that implement it. This is useful in environments that use centralized authentification when you want to manipulate the local groups. I.E. it uses `lgroupadd` instead of `useradd`.,This requires that these commands exist on the targeted host, otherwise it will be a fatal error.
system: no # not required. If I(yes), indicates that the group created is a system group.
- name: create New user.
user:
name: "{{ user_name }}" # required. Name of the user to create, remove or modify.
comment: ansible user # not required. Optionally sets the description (aka I(GECOS)) of user account.
create_home: yes # not required. Unless set to C(no), a home directory will be made for the user when the account is created or if the home directory does not exist.,Changed from C(createhome) to C(create_home) in version 2.5.
groups: "{{ groups_name }}"
home: /home/ansibleadmin # not required. Optionally set the user's home directory.
password: "{{ user_passwd }}" # not required. Optionally set the user's password to this crypted value.,On macOS systems, this value has to be cleartext. Beware of security issues.,See U(https://docs.ansible.com/ansible/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module) for details on various ways to generate these password values.
generate_ssh_key: no # not required. Whether to generate a SSH key for the user in question. This will B(not) overwrite an existing SSH key.
append: no # not required. If C(yes), add the user to the groups specified in C(groups).,If C(no), user will only be added to the groups specified in C(groups), removing them from all other groups.
uid: 1008 # not required. Optionally sets the I(UID) of the user.
group: "{{ groups_name }}" # not required. Optionally sets the user's primary group (takes a group name).
shell: /bin/bash # not required. Optionally set the user's shell.,On macOS, before version 2.5, the default shell for non-system users was /usr/bin/false. Since 2.5, the default shell for non-system users on macOS is /bin/bash.
state: present # not required. choices: absent;present. Whether the account should exist or not, taking action if the state is different from what is stated.
2,交互变量的使用
root@sam:/opt/# cat prompt_test.yml---
- hosts: ceph01
remote_user: root
vars_prompt:
- name: "your_name"
prompt: "what id your name"
private: no
- name: "your_age"
prompt: "how old are you"
private: no
- name: "solution"
prompt: "Choose the solution you want \n
A: solutionA\n
B: solutionB\n
C: solutionC\n"
private: no
default: A
- name: "user_name"
prompt: "Enter user name"
private: no
- name: "user_password" #存储数据的变量名
prompt: "Enter user password" #手工输入数据
private: no #当该值为yes,则用户的输入不会被打印
encrypt: "sha512_crypt"
confirm: yes
tasks:
- name: output vars
debug:
msg: "your name is {{ your_name }},you are {{ your_age }} years old."
- name: output solution
debug:
msg: the final solution is {{solution}}
- name: create_user
user:
name: "{{user_name}}"
password: "{{user_password}}"
- name: debug_create user
debug:
msg: "create user {{user_name}} in "
原文链接:https://blog.csdn.net/zuopiezia/java/article/details/100762399
转载请标明出处【ansible使用vars_prompt交互变量,user,group模块增加账号密码】。
《www.micoder.cc》
虚拟化云计算,系统运维,安全技术服务.
Tags: | [阅读全文...] |
最新评论