Dec.03

Ansible: Creating multiple user, Generating Password(sha512), expiring password(force user to change)

  tasks:
  - name: multiple
    user:
      name: "{{ item.name }}"
      shell: /bin/bash
      createhome: yes
      password: "{{ item.password | password_hash('sha512') }}"
      comment: "{{ item.comment }}"
      state: present
      update_password: on_create
    register: changes
    with_items:
     - { name: testuser1, password: testuser1@123, comment: "test user1" }
     - { name: testuser2, password: testuser2@123, comment: "test user2" }

  - name: Expire password
    shell: chage -d 0 {{ item.name }}
    with_items: "{{ changes.results }}"
    when: "{{ item.changed == true }}"

 



Share this Story:
  • facebook
  • twitter
  • gplus

About bentech4u

Leave a comment