Nov.27

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

As the subject says, here is the yml

tasks:
- name: Creating crm group
  group:
    name: crm
    state: present

- name: Add user testuser
  user:
    name: testuser
    comment: crm test user
    shell: /bin/bash
    home: /home/testuser
    state: present
    createhome: yes
    groups: crm
    password: "{{ 'crm@123' | password_hash('sha512') }}"
    update_password: on_create
  register: testuser

- name: Force testuser change password
  shell: chage -d 0 testuser
  when: testuser.changed

 

Share this Story:
  • facebook
  • twitter
  • gplus

About bentech4u

Leave a comment