Creating a new user and password with Ansible

后端 未结 22 1489
迷失自我
迷失自我 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条回答
  •  天命终不由人
    2020-12-22 17:30

    Just for completeness I will post the ad-hoc command using ansible since there is a catch there as well.

    First try generating an encrypted password using the mkpasswd utility that is available on most Linux systems:

    mkpasswd --method=SHA-512
    

    Then try the ansible ad-hock command:

    ansible all -m user -a 'name=testuser shell=/bin/bash \
         comment="Test User" password=$6$XXXX' -k -u admin --sudo
    

    But make sure:

    1. The command is in single quotes and NOT double otherwise your password will never work
    2. You run it with --sudo or you end up with an error like (useradd: cannot lock /etc/passwd; try again later)

提交回复
热议问题