记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。

1,var_prompt 提示用户输入信息,然后将用户输入的信息存入到指定的变量中,

--- 
name92cto hosts add New group and user.
  hostsmicoder.cc
  userroot
  gather_factsfalse

  vars_prompt:
   - name"groups_name"
     prompt"input New groups_name"
   - name"user_name"
     prompt"input New USER_NAME"
     privateno
   - name"user_passwd"
     prompt"Enter Password"
     encrypt"sha512_crypt"
     confirmyes

  tasks:
   - namecreate New group.
     group:
         name"{{ groups_name }}"
         statepresent # not required. choices: absent;present. Whether the group should be present or not on the remote host.
         gid1008 # not required. Optional I(GID) to set for the group.
         localno # 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.
         systemno # not required. If I(yes), indicates that the group created is a system group.
   - namecreate New user.
     user:
         name"{{ user_name }}" # required. Name of the user to create, remove or modify.
         commentansible user  # not required. Optionally sets the description (aka I(GECOS)) of user account.
         create_homeyes # 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_keyno # not required. Whether to generate a SSH key for the user in question. This will B(not) overwrite an existing SSH key.
         appendno # 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.
         uid1008 # 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.
         statepresent # 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》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论