Creating a new user and password with Ansible

后端 未结 22 1469
迷失自我
迷失自我 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:36

    I know that I'm late to the party, but there is another solution that I'm using. It might be handy for distros that don't have --stdin in passwd binary.

    - hosts: localhost
      become: True
      tasks:
        - name: Change user password
          shell: "yes '{{ item.pass }}' | passwd {{ item.user }}"
          loop:
           - { pass: 123123, user: foo }
           - { pass: asdf, user: bar }
          loop_control:
            label: "{{ item.user }}"
    

    Label in loop_control is responsible for printing only username. The whole playbook or just user variables (you can use vars_files:) should be encrypted with ansible-vault.

提交回复
热议问题