Creating a new user and password with Ansible

后端 未结 22 1539
迷失自我
迷失自我 2020-12-22 17:00

I have an ansible task which creates a new user on ubuntu 12.04;

- name: Add deployment user
    action: user name=deployer password=mypassword
22条回答
  •  长情又很酷
    2020-12-22 17:40

    I may be too late to reply this but recently I figured out that jinja2 filters have the capability to handle the generation of encrypted passwords. In my main.yml I'm generating the encrypted password as:

    - name: Creating user "{{ uusername }}" with admin access
      user: 
        name: {{ uusername }}
        password: {{ upassword | password_hash('sha512') }}
        groups: admin append=yes
      when:  assigned_role  == "yes"
    
    - name: Creating users "{{ uusername }}" without admin access
      user:
        name: {{ uusername }}
        password: {{ upassword | password_hash('sha512') }}
      when:  assigned_role == "no"
    
    - name: Expiring password for user "{{ uusername }}"
      shell: chage -d 0 "{{ uusername }}"
    

    "uusername " and "upassword " are passed as --extra-vars to the playbook and notice I have used jinja2 filter here to encrypt the passed password.

    I have added below tutorial related to this to my blog

    • https://thinkingmonster.wordpress.com/it-automation/386-2/ansible-roles/

提交回复
热议问题