
These two roles no longer need the delegation variable used in testing, so it is removed. Role execution now happens on the executor. Since the remote servers are still on the worker node, we open the firewall on the remote node in both cases. In the artifactory role, the ensure-docker role is moved to a "roles" section for simplicity. Additionally, one of the artifactory API calls is wrapped in retries as a precaution since I saw that fail in local testing. Change-Id: Ia4409edc217e1935775a5aece2e7d9bcfd935762
139 lines
4.7 KiB
YAML
139 lines
4.7 KiB
YAML
- hosts: all
|
|
roles:
|
|
- clear-firewall
|
|
- ensure-docker
|
|
tasks:
|
|
- name: Start artifactory in a container
|
|
command: >-
|
|
docker run -d
|
|
-p 8081:8081 -p 8082:8082
|
|
--name {{ zuul.build }}
|
|
docker.bintray.io/jfrog/artifactory-oss:7.77.12
|
|
|
|
- name: Wait for artifactory to start
|
|
uri:
|
|
url: http://localhost:8082/artifactory/api/system/ping
|
|
method: GET
|
|
register: artifactory_status
|
|
until: artifactory_status.status == 200
|
|
retries: 12
|
|
delay: 20
|
|
|
|
- name: Create a generic repository in artifactory
|
|
uri:
|
|
url: http://localhost:8082/artifactory/api/system/configuration
|
|
user: admin
|
|
password: password
|
|
force_basic_auth: true
|
|
method: PATCH
|
|
body: |
|
|
localRepositories:
|
|
generic-repository:
|
|
type: generic
|
|
headers:
|
|
Content-Type: application/yaml
|
|
until: artifactory_status.status == 200
|
|
retries: 12
|
|
delay: 20
|
|
|
|
- name: Create an api key for the admin user
|
|
uri:
|
|
url: http://localhost:8082/artifactory/api/security/apiKey
|
|
user: admin
|
|
password: password
|
|
status_code: 201
|
|
return_content: true
|
|
method: POST
|
|
register: artifactory_api_key
|
|
|
|
- name: Set artifactory instances fact
|
|
set_fact:
|
|
cacheable: true
|
|
upload_artifactory_instances:
|
|
localhost_password:
|
|
fqdn: "{{ ansible_host }}:8081"
|
|
transport: http
|
|
user: admin
|
|
password: password
|
|
force_basic_auth: true
|
|
localhost_api_key:
|
|
fqdn: "{{ ansible_host }}:8081"
|
|
transport: http
|
|
user: admin
|
|
api_key: "{{ (artifactory_api_key.content | from_json)['apiKey'] }}"
|
|
localhost_properties:
|
|
fqdn: "{{ ansible_host }}:8081"
|
|
transport: http
|
|
user: admin
|
|
api_key: "{{ (artifactory_api_key.content | from_json)['apiKey'] }}"
|
|
|
|
- hosts: all
|
|
pre_tasks:
|
|
- name: Create artifacts directory
|
|
delegate_to: "localhost"
|
|
file:
|
|
path: "{{ zuul.executor.work_root }}/artifacts"
|
|
state: directory
|
|
- name: Write a file with some content to artifacts directory
|
|
delegate_to: "localhost"
|
|
copy:
|
|
content: |
|
|
First file
|
|
dest: "{{ zuul.executor.work_root }}/artifacts/test-file.txt"
|
|
- name: Set upload_artifactory_manifest_basic fact
|
|
set_fact:
|
|
upload_artifactory_manifest:
|
|
artifacts:
|
|
- name: test-password.txt
|
|
src: test-file.txt
|
|
dest: generic-repository/path/to/dest/test-password.txt
|
|
instance: localhost_password
|
|
- name: test-api-key.txt
|
|
src: test-file.txt
|
|
dest: generic-repository/path/to/dest/test-api-key.txt
|
|
instance: localhost_api_key
|
|
- name: test-properties.txt
|
|
src: test-file.txt
|
|
dest: generic-repository/path/to/dest/test-properties.txt
|
|
instance: localhost_properties
|
|
properties:
|
|
version: 1.0.0
|
|
supports:
|
|
- 1.0.1
|
|
- 1.0.2
|
|
roles:
|
|
- role: upload-artifactory
|
|
|
|
post_tasks:
|
|
- name: Load artifacts information from zuul_return
|
|
set_fact:
|
|
artifacts: "{{ (lookup('file', zuul.executor.work_root + '/results.json') | from_json) ['data']['zuul']['artifacts'] }}"
|
|
- name: Expected artifacts are backwards
|
|
set_fact:
|
|
expected_artifacts:
|
|
- name: test-properties.txt
|
|
url: "http://{{ ansible_host }}:8081/artifactory/generic-repository/path/to/dest/test-properties.txt"
|
|
- name: test-api-key.txt
|
|
url: "http://{{ ansible_host }}:8081/artifactory/generic-repository/path/to/dest/test-api-key.txt"
|
|
- name: test-password.txt
|
|
url: "http://{{ ansible_host }}:8081/artifactory/generic-repository/path/to/dest/test-password.txt"
|
|
- name: Assert artifact
|
|
assert:
|
|
that:
|
|
- item.0.name == item.1.name
|
|
- item.0.url == item.1.url
|
|
loop: "{{ artifacts | zip(expected_artifacts) | list }}"
|
|
|
|
- name: Query properties artifact
|
|
uri:
|
|
method: POST
|
|
url: 'http://localhost:8081/artifactory/api/search/aql'
|
|
headers:
|
|
X-JFrog-Art-Api: "{{ (artifactory_api_key.content | from_json)['apiKey'] }}"
|
|
Content-Type: 'text/plain'
|
|
body: 'items.find({"$and":[{"repo":"generic-repository"},{"path":"path/to/dest"},{"@version":"1.0.0"}]})'
|
|
register: artifact_query
|
|
- name: Assert property filtered response
|
|
assert:
|
|
that: artifact_query.json.results[0].name == 'test-properties.txt'
|