我如何创建一个用户(不是硬编码的)到一个已有的组并提示新用户输入他的新密码?

时间:2018-08-26 14:00:54

标签: ansible

我是ansible的新手,这是我正在从事的项目。到目前为止,下面的代码是我放在一起的。此代码有效,但是密码未注册,当我使用创建的新用户登录时。它说验证失败。请帮助

---
- hosts: box432
  gather_facts: false
  vars_prompt:
   - name: 'creating user with password'
     prompt: 'enter password for user'
     private: yes
     encrypt: sha512_crypt
     confirm: yes
     salt_size: 7
  tasks:
  -  pause: prompt="enter user name"
     register: user_name
  -  name: "Print"
     debug: msg="{{ user_name }}"
  -  name: updating user password
     become: true
     user:
        name: "{{ user_name }}"
        state: present
        groups: stackflow

1 个答案:

答案 0 :(得分:0)

首先,name中的vars_prompt不是任意注释,而是要设置的变量的名称,因此本节应为:

vars_prompt:
  - name: "provided_password"
    prompt: "enter password for user"
    private: yes
    encrypt: sha512_crypt
    confirm: yes
    salt_size: 7

第二,在您的代码中,您甚至没有尝试使用该变量。您应该在password参数中提供值:

- name: updating user password
  become: true
  user:
    name: "{{ user_name }}"
    password: "{{ provided_password }}"
    state: present
    groups: stackflow