0x00000001


Ansible mkpasswd role

default.yml

- hosts: localhost
  pre_tasks:

    - set_fact:
        target_host: "localhost"

  roles:
    - { role: misc.mkpasswd,
        password_samples: 20,
        password_length: 40,
        target_host: "localhost",
        env: 'dev' }

    - misc.mkpasswd

  post_tasks:
    - debug: msg=""

tasks/main.yml

- name: Reset variables (password_samples)
  set_fact:
    misc_mkpasswd_password_samples: ""
  when: password_samples is defined and password_samples > 0

- name: Reset variables (password_length)
  set_fact:
    misc_mkpasswd_password_length: ""
  when: password_length is defined and password_length > 0

- name: Reset variables (delegate_to)
  set_fact:
    misc_mkpasswd_delegate_to: ""
  when: target_host is defined and (target_host | length) > 0

- name: Reset variables (env)
  set_fact:
    env: 'dev'
  when: not(env is defined)

- name: Reset variables
  set_fact:
    misc_mkpasswd_rand_pw_string: ''

- name: Generate new random password
  shell: </dev/urandom tr -dc '1234567890qwertyuiopQWERTYUIOPasdfghjklASDFGHJKLzxcvbnmZXCVBNM*_!#&$%' | head -c; echo
  register: misc_mkpasswd_rand_pw_string
  delegate_to: ""
  with_sequence: start=0 end=
  no_log: ""

- name: Pick password
  set_fact:
    misc_mkpasswd_rand_pw_string: ""

- name: The new password is
  debug:
    msg: ""
  when: env == 'dev'