Creating a new user and password with Ansible

后端 未结 22 1481
迷失自我
迷失自我 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条回答
  •  萌比男神i
    2020-12-22 17:33

    Generating random password for user

    first need to define users variable then follow below

    tasks:

    - name: Generate Passwords
      become: no
      local_action: command pwgen -N 1 8
      with_items: '{{ users }}'
      register: user_passwords
    
    - name: Update User Passwords
      user:
        name: '{{ item.item }}'
        password: "{{ item.stdout | password_hash('sha512')}}"
        update_password: on_create
      with_items: '{{ user_passwords.results }}'
    
    - name: Save Passwords Locally
      become: no
      local_action: copy content={{ item.stdout }} dest=./{{ item.item }}.txt
      with_items: '{{ user_passwords.results }}'
    

提交回复
热议问题