zuul-jobs/roles/promote-docker-image/tasks/promote-cleanup.yaml
Albin Vass d0e2016592 Add loop var policy to ansible-lint
This adds a custom ansible-lint rule at .rules/ZuulJobsNamespaceLoopVar.py
that enforces the loop var policy described at:
https://zuul-ci.org/docs/zuul-jobs/policy.html#ansible-loops-in-roles

It also updates existing roles to follow the policy.

Change-Id: I92b2ff56a1c2702542fc07b316f1809087a4c92f
2020-04-29 17:20:59 +02:00

21 lines
825 B
YAML

- name: List tags
uri:
url: "https://hub.docker.com/v2/repositories/{{ image.repository }}/tags?page_size=1000"
status_code: 200
register: tags
- name: Set cutoff timestamp to 24 hours ago
command: "python3 -c \"import datetime; print((datetime.datetime.utcnow()-datetime.timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%fZ'))\""
register: cutoff
- name: Delete all change tags older than the cutoff
no_log: true
loop: "{{ tags.json.results }}"
loop_control:
loop_var: zj_docker_tag
when: zj_docker_tag.last_updated < cutoff.stdout and zj_docker_tag.name.startswith('change_')
uri:
url: "https://hub.docker.com/v2/repositories/{{ image.repository }}/tags/{{ zj_docker_tag.name }}/"
method: DELETE
status_code: [200,204]
headers:
Authorization: "JWT {{ jwt_token.json.token }}"