--- - name: Remove repo directory file: path: /tmp/do417 state: absent - name: Install acl yum: name: acl state: present use_backend: dnf become: true - name: Get ssh key for Github copy: src: "{{ github_ssh_key }}" dest: /tmp/github_ssh_key mode: 0400 owner: "{{ ansible_user }}" - name: Get lab source code git: clone: yes force: yes dest: "/tmp/do417" repo: "git@github.com:RedHatTraining/do417.git" key_file: /tmp/github_ssh_key accept_hostkey: true - name: Remove ssh key for Github file: path: /tmp/github_ssh_key state: absent - name: Remove .git directory file: path: /tmp/do417/.git state: absent - name: Determining material directories command: find /tmp/do417/classroom/infrastructure/playbooks/files/src -maxdepth 1 -mindepth 1 -type d -printf '%f\n' register: repos_name - name: Retrieve access token uri: url: "https://localhost/oauth/token" method: POST validate_certs: no status_code: 200 body_format: json headers: Content-Type: application/json body: > { "grant_type": "password", "username": "root", "password": "{{ windows_password }}" } register: gitlab_access_token - name: Retrieve local user information via API uri: url: https://localhost/api/v4/users?username={{ user_prefix }} method: GET validate_certs: no status_code: - 200 - 201 headers: Content-Type: application/json Authorization: Bearer {{ gitlab_access_token.json.access_token }} register: gitlab_local_users - name: Create projects via API uri: url: https://localhost/api/v4/projects/user/{{ gitlab_local_users.json[0].id }} method: POST validate_certs: no status_code: - 200 - 201 - 409 - 400 body_format: json headers: Content-Type: application/json Authorization: Bearer {{ gitlab_access_token.json.access_token }} body: > { "name": "{{ item }}", "group": "{{ gitlab_local_users.json[0].name }}", "issues_enabled": false, "wiki_enabled": true, "snippets_enabled": true } with_items: "{{ repos_name.stdout_lines }}" when: gitlab_local_users.json[0].id is defined - name: Configure local account shell: | git config --global http.sslVerify false git config --global user.email student@example.com git config --global user.name student - name: Delete previous directories if present file: path: "/tmp/{{ item }}" state: absent with_items: "{{ repos_name.stdout_lines }}" - name: Clone repositories git: repo: https://{{ user_prefix | urlencode }}:{{ windows_password | urlencode }}@localhost/student/{{ item }}.git dest: "/tmp/{{ item }}/" clone: yes with_items: "{{ repos_name.stdout_lines }}" ignore_errors: true - name: Copying files for repositories copy: src: "/tmp/do417/classroom/infrastructure/playbooks/files/src/{{ item }}/" dest: "/tmp/{{ item }}/" remote_src: true with_items: "{{ repos_name.stdout_lines }}" - name: ({{ repo_name }}) - Creating dummy file copy: dest: "/tmp/{{ item }}/dummy.yml" content: | --- - name: Dummy playbook hosts: all tasks: - name: Print Hello World debug: msg: 'Hello World' with_items: "{{ repos_name.stdout_lines }}" - name: Load files into repositories shell: | git init git remote add origin https://{{ user_prefix | urlencode }}:{{ windows_password | urlencode }}@localhost/student/{{ item }}.git git add . git commit -m 'Establish initial {{ item }} repository' git push -u origin HEAD:master exit 0 args: chdir: "/tmp/{{ item }}" with_items: "{{ repos_name.stdout_lines }}"