# # task: create deployer # # # @author Björn Hase # - name: Check if users exist getent: database: passwd key: deploy fail_key: false - name: create password set_fact: password="{{ lookup('ansible.builtin.password', '~/deploy.txt', length=30, chars=['ascii_letters', 'digits']) }}" # # create user if not exists # - name: create user user: name: deploy password: "{{ password }}" create_home: yes when: ansible_facts.getent_passwd|bool == false # # create ssh-key add to authorized_keys as deploy user # - stat: path: ~/.ssh/git become_user: deploy register: git_key - name: create ssh shell: | ssh-keygen -t ed25519 -f ~/.ssh/git -C $(hostname) -q -P "" cat ~/.ssh/git.pub >> ~/.ssh/authorized_keys become_user: deploy when: ansible_facts.getent_passwd|bool == false and not git_key.stat.exists