Creating a new user and password with Ansible

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

    You can use ansible-vault for using secret keys in playbooks. Define your password in yml.

    ex. pass: secret or

    user:
      pass: secret
      name: fake
    

    encrypt your secrets file with :

    ansible-vault encrypt /path/to/credential.yml

    ansible will ask a password for encrypt it. (i will explain how to use that pass)

    And then you can use your variables where you want. No one can read them without vault-key.

    Vault key usage:

    via passing argument when running playbook.

    --ask-vault-pass: secret
    

    or you can save into file like password.txt and hide somewhere. (useful for CI users)

    --vault-password-file=/path/to/file.txt
    

    In your case : include vars yml and use your variables.

    - include_vars: /path/credential.yml
    
      - name: Add deployment user
        action: user name={{user.name}} password={{user.pass}}
    

提交回复
热议问题