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 }}"

 



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