Creating a new user and password with Ansible

后端 未结 22 1479
迷失自我
迷失自我 2020-12-22 17:00

I have an ansible task which creates a new user on ubuntu 12.04;

- name: Add deployment user
    action: user name=deployer password=mypassword
22条回答
  •  旧时难觅i
    2020-12-22 17:23

    How to create encrypted password for passing to password var to Ansible user task (from @Brendan Wood's comment):

    openssl passwd -salt 'some_plain_salt' -1 'some_plain_pass'
    

    The result will look like:

    $1$some_pla$lmVKJwdV3Baf.o.F0OOy71
    

    Example of user task:

    - name: Create user
      user: name="my_user" password="$1$some_pla$lmVKJwdV3Baf.o.F0OOy71"
    

    UPD: crypt using SHA-512 see here and here:

    Python

    $ python -c "import crypt, getpass, pwd; print crypt.crypt('password', '\$6\$saltsalt\$')"
    
    $6$saltsalt$qFmFH.bQmmtXzyBY0s9v7Oicd2z4XSIecDzlB5KiA2/jctKu9YterLp8wwnSq.qc.eoxqOmSuNp2xS0ktL3nh/
    

    Perl

    $ perl -e 'print crypt("password","\$6\$saltsalt\$") . "\n"'
    
    $6$saltsalt$qFmFH.bQmmtXzyBY0s9v7Oicd2z4XSIecDzlB5KiA2/jctKu9YterLp8wwnSq.qc.eoxqOmSuNp2xS0ktL3nh/
    

    Ruby

    $ ruby -e 'puts "password".crypt("$6$saltsalt$")'
    
    $6$saltsalt$qFmFH.bQmmtXzyBY0s9v7Oicd2z4XSIecDzlB5KiA2/jctKu9YterLp8wwnSq.qc.eoxqOmSuNp2xS0ktL3nh/
    

提交回复
热议问题