| --- |
| - name: Create and update repositories in BitBucket |
| hosts: localhost |
| connection: local |
| vars_files: |
| - repository-mapping-name-folder.yml |
| - repository-custom-properties.yml |
| - private-repository-user-list.yml |
| tasks: |
| # - name: Remove Gitlab repositories if necessary |
| # tags: ['create'] |
| # register: repos |
| # uri: |
| # url: "{{ repository_secure_endpoint_https }}/projects/Daniel.Mangino.1233964715/{{ item }}" |
| # method: DELETE |
| # headers: |
| # PRIVATE-TOKEN: "{{ token }}" |
| # status_code: 201,404 |
| # with_items: |
| # - "Delete-ME" |
| |
| - name: Create Gitlab repositories if necessary |
| tags: ['create'] |
| register: repos |
| uri: |
| url: "{{ repository_secure_endpoint_https }}/projects?name={{ item }}" |
| method: POST |
| headers: |
| PRIVATE-TOKEN: "{{ token }}" |
| status_code: 201 |
| with_items: |
| - "Delete-ME" |
| # - "{{ config_repos }}" |
| # - "{{ playbook_repos }}" |
| # - "{{ role_repos }}" |
| |
| - name: Show repos structure |
| tags: ['create'] |
| debug: |
| var: repos |
| |
| - name: Pause to show debug output |
| pause: |
| |
| |
| - name: Share repos with group |
| tags: ['create'] |
| uri: |
| url: "{{ repository_secure_endpoint_https }}/projects/{{ repos.results[0].json.id }}/share" |
| method: POST |
| headers: |
| PRIVATE-TOKEN: "{{ token }}" |
| status_code: 201,409 |
| body_format: json |
| body: |
| group_id: api-management |
| group_access: 30 |
| expires_at: 2018-04-30 |
| |
| - name: Add permissions to Bitbucket repositories |
| uri: |
| url: "{{ repository_secure_endpoint_https }}/permissions/users?name={{ item }}&permission=PROJECT_ADMIN" |
| method: PUT |
| user: "{{ username }}" |
| password: "{{ password }}" |
| force_basic_auth: yes |
| status_code: 204,409 |
| with_items: "{{ repo_users }}" |
| |
| - name: Add second git host as remote repo |
| ignore_errors: true |
| shell: "git remote add target {{ repository_secure_endpoint_ssh }}/{{ item.repo_name }}.git" |
| args: |
| chdir: "{{ item.workspace }}/{{ item.repo_name }}" |
| with_items: "{{ repo_names }}" |
| |
| - name: Pull from second git host if the repo is already there |
| ignore_errors: yes |
| shell: "git pull target master" |
| args: |
| chdir: "{{ item.workspace }}/{{ item.repo_name }}" |
| with_items: "{{ repo_names }}" |
| |
| - name: Commit updated repos to second git host |
| shell: "git checkout master && git push -u target master" |
| args: |
| chdir: "{{ item.workspace }}/{{ item.repo_name }}" |
| with_items: "{{ repo_names }}" |