system-config/playbooks/roles/gitea-set-org-logos/tasks/main.yaml
Ian Wienand 65856979f8
gitea-set-org-logos: use -T on mariadb command
For some reason something about running under Ansible 6 trips this up
and fails with "unable to allocate a TTY", whereas the old version
didn't.  Tell it not to allocate a tty.

Change-Id: Iceb3686d6c00380f4ffba0be8a7af7abd10f8f8b
2022-11-23 08:26:28 +11:00

49 lines
1.5 KiB
YAML

- name: Get list of orgs
uri:
url: 'https://localhost:3000/api/v1/orgs'
method: GET
user: root
password: '{{ gitea_root_password }}'
return_content: yes
validate_certs: false
status_code: 200
body_format: json
register: _org_list_raw
no_log: True
- name: Filter org list
set_fact:
_org_list: '{{ _org_list_raw.json | map(attribute="username") | list }}'
- name: Copy org logos
copy:
src: '{{ lookup("first_found", _org_logos) }}'
dest: '/var/gitea/data/gitea/avatars/{{ item }}'
owner: 1000
group: 1000
mode: 0644
vars:
_org_logos:
- '{{ item }}.png'
- 'default.png'
loop: '{{ _org_list }}'
register: _logos_updated
- name: Get changed logos
set_fact:
_changed_logos: '{{ _logos_updated.results | selectattr("changed", "equalto", true) | map(attribute="item") | list }}'
# NOTE(ianw) 2022-03-17 There is currently no API to update avatar
# logos with gitea, so we direct update for now.
# * orgs are just entries in the "users" table
# * the "avatar" field is a plain-text name of a file in
# /var/gitea/data/gitea/avatars
- name: Run update query
shell: >-
/usr/local/bin/docker-compose -f /etc/gitea-docker/docker-compose.yaml
exec -T mariadb bash -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e
"USE gitea; UPDATE user SET avatar = '\''{{ item }}'\'', use_custom_avatar = 1 WHERE name = '\''{{ item }}'\''"'
args:
executable: '/bin/bash'
loop: '{{ _changed_logos }}'