s3_registry.yml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. ---
  2. # This playbook creates an S3 bucket named after your cluster and configures the docker-registry service to use the bucket as its backend storage.
  3. # Usage:
  4. # ansible-playbook s3_registry.yml -e clusterid="mycluster"
  5. #
  6. # The AWS access/secret keys should be the keys of a separate user (not your main user), containing only the necessary S3 access role.
  7. # The 'clusterid' is the short name of your cluster.
  8. - hosts: tag_clusterid_{{ clusterid }}:&tag_host-type_openshift-master
  9. remote_user: root
  10. gather_facts: False
  11. vars:
  12. aws_access_key: "{{ lookup('env', 'S3_ACCESS_KEY_ID') }}"
  13. aws_secret_key: "{{ lookup('env', 'S3_SECRET_ACCESS_KEY') }}"
  14. tasks:
  15. - name: Check for AWS creds
  16. fail:
  17. msg: "Couldn't find {{ item }} creds in ENV"
  18. when: "{{ item }} == ''"
  19. with_items:
  20. - aws_access_key
  21. - aws_secret_key
  22. - name: Scale down registry
  23. command: oc scale --replicas=0 dc/docker-registry
  24. - name: Create S3 bucket
  25. local_action:
  26. module: s3 bucket="{{ clusterid }}-docker" mode=create
  27. - name: Set up registry environment variable
  28. command: oc env dc/docker-registry REGISTRY_CONFIGURATION_PATH=/etc/registryconfig/config.yml
  29. - name: Generate docker registry config
  30. template: src="s3_registry.j2" dest="/root/config.yml" owner=root mode=0600
  31. - name: Determine if new secrets are needed
  32. command: oc get secrets
  33. register: secrets
  34. - name: Create registry secrets
  35. command: oc secrets new dockerregistry /root/config.yml
  36. when: "'dockerregistry' not in secrets.stdout"
  37. - name: Determine if service account contains secrets
  38. command: oc describe serviceaccount/registry
  39. register: serviceaccount
  40. - name: Add secrets to registry service account
  41. command: oc secrets add serviceaccount/registry secrets/dockerregistry
  42. when: "'dockerregistry' not in serviceaccount.stdout"
  43. - name: Determine if deployment config contains secrets
  44. command: oc volume dc/docker-registry --list
  45. register: dc
  46. - name: Add secrets to registry deployment config
  47. command: oc volume dc/docker-registry --add --name=dockersecrets -m /etc/registryconfig --type=secret --secret-name=dockerregistry
  48. when: "'dockersecrets' not in dc.stdout"
  49. - name: Wait for deployment config to take effect before scaling up
  50. pause: seconds=30
  51. - name: Scale up registry
  52. command: oc scale --replicas=1 dc/docker-registry
  53. - name: Delete temporary config file
  54. file: path=/root/config.yml state=absent