--- ### tags: ### awx_config ### awx_repository - name: "Remove all " include_tasks: awx-config-cleanup.yml vars: awx_rest_api_type: job_templates when: (awx_hetzner_ansible_project_id is not defined) tags: - awx_config - name: "Printing..." debug: msg: "{{ ansible_ssh_key_private }}" delegate_to: 127.0.0.1 become: false when: - debug tags: - awx_config - name: "Authenticating with awx server" uri: url: "{{ awx_base_url }}/api/v2/me/" method: GET user: "{{ awx_rest_api_access_user }}" password: "{{ awx_rest_api_access_pw }}" return_content: true validate_certs: false force_basic_auth: yes status_code: 200 tags: - awx_config - name: "Search user <{{ awx_ansible_username }}>" include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: users awx_search_key: username awx_search_name: "{{ awx_ansible_username }}" tags: - awx_config - name: "Update ansible_awx_user_id" set_fact: ansible_awx_user_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Add user <{{ awx_ansible_username }}>" vars: username: "{{ awx_ansible_username }}" password: "{{ awx_ansible_password }}" uri: url: "{{ awx_base_url }}/api/v2/users/" method: POST user: "{{ awx_rest_api_access_user }}" password: "{{ awx_rest_api_access_pw }}" headers: Content-Type: "application/json" Accept: "application/json" body_format: "json" body: "{{ lookup('template','awx-create-user.json.j2') }}" force_basic_auth: true validate_certs: false status_code: 201 register: response changed_when: response.status == 201 when: ansible_awx_user_id is not defined tags: - awx_config - name: "Search user <{{ awx_ansible_username }}>" include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: users awx_search_key: username awx_search_name: "{{ awx_ansible_username }}" when: ansible_awx_user_id is not defined tags: - awx_config - name: "Update ansible_awx_user_id" set_fact: ansible_awx_user_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Remove all " include_tasks: awx-config-cleanup.yml vars: awx_rest_api_type: credentials tags: - awx_config - name: "Search credential type id for " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: credential_types awx_search_key: name awx_search_name: "Machine" tags: - awx_config - name: "Update awx_credential_type_machine_id" set_fact: awx_credential_type_machine_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Search credentials " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: credentials awx_search_key: name awx_search_name: "hetzner-ansible-ssh" tags: - awx_config - name: "Update awx_credential_hetzner_ansible_id" set_fact: awx_credential_hetzner_ansible_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Add credentials " vars: name: "hetzner-ansible-ssh" user_id: "{{ ansible_awx_user_id }}" credential_type_id: "{{ awx_credential_type_machine_id }}" credential_type_name: "Machine" username: "Ansible" ssh_public_key_data: "{{ lookup('file', '{{ playbook_dir }}/users/ansible/ssh.pub') }}" ssh_key_data: "{{ ansible_ssh_key_private | replace('\n','\\n') }}" uri: url: "{{ awx_base_url }}/api/v2/credentials/" method: POST user: "{{ awx_rest_api_access_user }}" password: "{{ awx_rest_api_access_pw }}" headers: Content-Type: "application/json" Accept: "application/json" body_format: "json" body: "{{ lookup('template','awx-create-credential.json.j2') }}" force_basic_auth: true validate_certs: false status_code: 201 register: response changed_when: response.status == 201 when: awx_credential_hetzner_ansible_id is not defined tags: - awx_config - name: "Search credentials " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: credentials awx_search_key: name awx_search_name: "hetzner-ansible-ssh" when: awx_credential_hetzner_ansible_id is not defined tags: - awx_config - name: "Update awx_credential_hetzner_ansible_id" set_fact: awx_credential_hetzner_ansible_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Search credential type id for " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: credential_types awx_search_key: name awx_search_name: "Vault" tags: - awx_config - name: "Update awx_credential_type_vault_id" set_fact: awx_credential_type_vault_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Search credentials " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: credentials awx_search_key: name awx_search_name: "hetzner-ansible-vault" tags: - awx_config - name: "Update awx_credential_hetzner_ansible_vault_id" set_fact: awx_credential_hetzner_ansible_vault_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Add credentials " vars: name: "hetzner-ansible-vault" user_id: "{{ ansible_awx_user_id }}" credential_type_id: "{{ awx_credential_type_vault_id }}" credential_type_name: "Vault" vault_password: "{{ ansible_vault_password }}" uri: url: "{{ awx_base_url }}/api/v2/credentials/" method: POST user: "{{ awx_rest_api_access_user }}" password: "{{ awx_rest_api_access_pw }}" headers: Content-Type: "application/json" Accept: "application/json" body_format: "json" body: "{{ lookup('template','awx-create-credential.json.j2') }}" force_basic_auth: true validate_certs: false status_code: 201 register: response changed_when: response.status == 201 when: awx_credential_hetzner_ansible_vault_id is not defined tags: - awx_config - name: "Search credentials " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: credentials awx_search_key: name awx_search_name: "hetzner-ansible-vault" when: awx_credential_hetzner_ansible_vault_id is not defined tags: - awx_config - name: "Update awx_credential_hetzner_ansible_vault_id" set_fact: awx_credential_hetzner_ansible_vault_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Search credential type id for " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: credential_types awx_search_key: name awx_search_name: "Container Registry" tags: - awx_config - name: "Update awx_credential_type_container_registry_id" set_fact: awx_credential_type_container_registry_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Search credentials <{{ shared_service_harbor_hostname }}>" include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: credentials awx_search_key: name awx_search_name: "{{ shared_service_harbor_hostname }}" tags: - awx_config - name: "Update awx_credential_harbor_id" set_fact: awx_credential_harbor_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Add credentials <{{ shared_service_harbor_hostname }}>" vars: name: "{{ shared_service_harbor_hostname }}" description: "{{ shared_service_harbor_hostname }}" user_id: "{{ ansible_awx_user_id }}" credential_type_id: "{{ awx_credential_type_container_registry_id }}" credential_type_name: "Container Registry" host: "{{ shared_service_harbor_hostname }}" username: "{{ harbor_username }}" password: "{{ harbor_token }}" uri: url: "{{ awx_base_url }}/api/v2/credentials/" method: POST user: "{{ awx_rest_api_access_user }}" password: "{{ awx_rest_api_access_pw }}" headers: Content-Type: "application/json" Accept: "application/json" body_format: "json" body: "{{ lookup('template','awx-create-credential.json.j2') }}" force_basic_auth: true validate_certs: false status_code: 201 register: response changed_when: response.status == 201 when: awx_credential_harbor_id is not defined tags: - awx_config - name: "Search credentials <{{ shared_service_harbor_hostname }}>" include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: credentials awx_search_key: name awx_search_name: "{{ shared_service_harbor_hostname }}" when: awx_credential_harbor_id is not defined tags: - awx_config - name: "Update awx_credential_harbor_id" set_fact: awx_credential_harbor_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Remove all " include_tasks: awx-config-cleanup.yml vars: awx_rest_api_type: execution_environments tags: - awx_config - name: "Search execution environment for " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: execution_environments awx_search_key: name awx_search_name: "hetzner-ansible" tags: - awx_config - name: "Update awx_ee_hetzner_ansible_id" set_fact: awx_ee_hetzner_ansible_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Add execution environment " vars: name: "hetzner-ansible" description: "hetzner-ansible" image: "{{ shared_service_harbor_hostname }}/awx/awx-custom-ee" credential: "{{ awx_credential_harbor_id }}" pull: "always" uri: url: "{{ awx_base_url }}/api/v2/execution_environments/" method: POST user: "{{ awx_rest_api_access_user }}" password: "{{ awx_rest_api_access_pw }}" headers: Content-Type: "application/json" Accept: "application/json" body_format: "json" body: "{{ lookup('template','awx-create-execution-environment.json.j2') }}" force_basic_auth: true validate_certs: false status_code: 201 register: response changed_when: response.status == 201 when: awx_ee_hetzner_ansible_id is not defined tags: - awx_config - name: "Search execution environment for " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: execution_environments awx_search_key: name awx_search_name: "hetzner-ansible" when: awx_ee_hetzner_ansible_id is not defined tags: - awx_config - name: "Update awx_ee_hetzner_ansible_id" set_fact: awx_ee_hetzner_ansible_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Remove all " include_tasks: awx-config-cleanup.yml vars: awx_rest_api_type: inventories tags: - awx_config - name: "Search inventory " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: inventories awx_search_key: name awx_search_name: "localhost" tags: - awx_config - name: "Update awx_localhost_inventory_id" set_fact: awx_localhost_inventory_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Add inventory " vars: name: "localhost" description: "localhost" uri: url: "{{ awx_base_url }}/api/v2/inventories/" method: POST user: "{{ awx_rest_api_access_user }}" password: "{{ awx_rest_api_access_pw }}" headers: Content-Type: "application/json" Accept: "application/json" body_format: "json" body: "{{ lookup('template','awx-create-inventory.json.j2') }}" force_basic_auth: true validate_certs: false status_code: 201 register: response changed_when: response.status == 201 when: awx_localhost_inventory_id is not defined tags: - awx_config - name: "Search inventory " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: inventories awx_search_key: name awx_search_name: "localhost" when: awx_localhost_inventory_id is not defined tags: - awx_config - name: "Update awx_localhost_inventory_id" set_fact: awx_localhost_inventory_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Create archive for repository " # noqa git-latest delegate_to: 127.0.0.1 git: archive: /tmp/hetzner-ansible.tar.gz dest: /tmp/gitrepo/ repo: "{{ playbook_dir }}" version: HEAD become: false tags: - awx_config - awx_repository - name: "Remove old repository folder for " file: state: absent path: "{{ awx_project_path }}/hetzner-ansible" tags: - awx_config - awx_repository - name: "Create project folder for " file: path: "{{ awx_project_path }}/hetzner-ansible" state: directory owner: root group: root mode: '0555' tags: - awx_config - awx_repository - name: "Extract repository archive for " unarchive: src: /tmp/hetzner-ansible.tar.gz dest: "{{ awx_project_path }}/hetzner-ansible" tags: - awx_config - awx_repository - name: "Remove temporarily local created files" delegate_to: 127.0.0.1 become: false file: state: absent path: '{{ item }}' loop: - /tmp/hetzner-ansible.tar.gz - /tmp/gitrepo tags: - awx_config - awx_repository - name: "Remove all " include_tasks: awx-config-cleanup.yml vars: awx_rest_api_type: projects tags: - awx_config - name: "Search project " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: projects awx_search_key: name awx_search_name: "hetzner-ansible" tags: - awx_config - name: "Update awx_hetzner_ansible_project_id" set_fact: awx_hetzner_ansible_project_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Add project " vars: name: "hetzner-ansible" description: "hetzner-ansible" local_path: "hetzner-ansible" default_environment_id: "{{ awx_ee_hetzner_ansible_id }}" uri: url: "{{ awx_base_url }}/api/v2/projects/" method: POST user: "{{ awx_rest_api_access_user }}" password: "{{ awx_rest_api_access_pw }}" headers: Content-Type: "application/json" Accept: "application/json" body_format: "json" body: "{{ lookup('template','awx-create-project.json.j2') }}" force_basic_auth: true validate_certs: false status_code: 201 register: response changed_when: response.status == 201 when: awx_hetzner_ansible_project_id is not defined tags: - awx_config - name: "Search project " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: projects awx_search_key: name awx_search_name: "hetzner-ansible" when: (awx_hetzner_ansible_project_id is not defined) tags: - awx_config - name: "Update awx_hetzner_ansible_project_id" set_fact: awx_hetzner_ansible_project_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Remove all " include_tasks: awx-config-cleanup.yml vars: awx_rest_api_type: job_templates tags: - awx_config - name: "Setting job templates credentials as fact" set_fact: job_templates_credentials: [ "{{ awx_credential_hetzner_ansible_vault_id }}", "{{ awx_credential_hetzner_ansible_id }}", ] tags: - awx_config - name: "Create job templates" include_tasks: awx-config-job-template.yml loop: "{{ awx_job_templates | flatten(levels=1) }}" loop_control: loop_var: job tags: - awx_config