This commit is contained in:
olli 2024-05-29 14:28:51 +02:00
parent 9ebe030804
commit 16c8ca7411

View File

@ -11,6 +11,49 @@
state: directory state: directory
mode: '0770' mode: '0770'
- name: /home/docker/portainer.{{inventory_hostname}}/genpw.sh (generate Random)
blockinfile:
path: /home/docker/portainer.{{inventory_hostname}}/genpw.sh
create: yes
mode: 0550
owner: root
group: docker
marker: "# {mark} ANSIBLE MANAGED BLOCK"
block: |
cd /home/docker/portainer.{{inventory_hostname}}
if [ -f env ]
then
. ./env
echo "${WEBPASSWDCRYPT}"
else
webpassword=$(pwgen -s 32 1)
webpasswordcrypted=$(htpasswd -nbB foo $webpassword | cut -d: -f2)
echo "WEBUSER=admin
WEBPASSWD=${webpassword}
WEBPASSWDCRYPT=${webpasswordcrypted}
" >env
chmod 440 env
chown root:docker env
echo "${webpasswordcrypted}"
fi
backup: yes
validate: /bin/bash -n %s
- name: /home/docker/portainer.{{inventory_hostname}}/genpw.sh shebang
lineinfile:
path: /home/docker/portainer.{{inventory_hostname}}/genpw.sh
insertbefore: BOF
line: "#!/bin/bash -e"
- name: Get crypted PW
shell: bash /home/docker/portainer.{{inventory_hostname}}/genpw.sh
register: cryptpw
changed_when: false
- name: /home/docker/portainer/docker-compose.yml Portainer Container Configuration - name: /home/docker/portainer/docker-compose.yml Portainer Container Configuration
blockinfile: blockinfile:
path: /home/docker/portainer/docker-compose.yml path: /home/docker/portainer/docker-compose.yml
@ -25,7 +68,7 @@
portainer: portainer:
image: portainer/portainer-ce:latest image: portainer/portainer-ce:latest
# htpasswd -nb -B admin "PASSWORD" | cut -d ":" -f 2 | sed -e s/\\$/\\$\\$/g # htpasswd -nb -B admin "PASSWORD" | cut -d ":" -f 2 | sed -e s/\\$/\\$\\$/g
command: --admin-password $$2y$$05$$zpNgDI6UufemwrBAg022QezGKJKFGziKudMjVdcHvQMFkiL1jmJCm command: --admin-password {{ cryptpw.stdout }}
restart: unless-stopped restart: unless-stopped
networks: networks:
- traefik - traefik