You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
887 B

#
# task: create deployer
#
#
# @author Björn Hase <herrhase@node001.net>
#
- 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