Ansible: Generate random password on MacOS for user creation

From Glitchdata
Jump to navigation Jump to search

Use openssl to auto-generate passwords on MacOS...

  vars:
    - name: Generate Random Password
      shell: openssl rand -base64 12
      register: random_password

  tasks:
  - name: Add group control
    group: name=control state=present

  - name: Add basic user control
    user: name=control group=control password= ${random_password.stdout} createhome=yes shell=/bin/bash

  - name: Add SSH keys to Control
    authorized_key:
      user=control
      key="{{lookup('file, "~/.ssh/id_rsa.pub")}}"


Related