--- - name: "Printing..." debug: msg: "{{ ansible_ssh_key_private }}" delegate_to: 127.0.0.1 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: "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/id_rsa.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: "{{ vault_ansible_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 " include_tasks: awx-config-get-typ-id.yml vars: awx_rest_api_type: credentials awx_search_key: name awx_search_name: "dev-docker-registry-01.smardigo.digital" tags: - awx_config - name: "Update awx_credential_docker_registry_id" set_fact: awx_credential_docker_registry_id: "{{ awx_type_id }}" when: - awx_type_id != "None" tags: - awx_config - name: "Add credentials " vars: name: "{{ shared_service_docker_registry_hostname }}" description: "{{ shared_service_docker_registry_hostname }}" user_id: "{{ ansible_awx_user_id }}" credential_type_id: "{{ awx_credential_type_container_registry_id }}" credential_type_name: "Container Registry" host: "{{ shared_service_docker_registry_hostname }}" username: "{{ docker_registry_username }}" password: "{{ docker_registry_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_docker_registry_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: "dev-docker-registry-01.smardigo.digital" when: awx_credential_docker_registry_id is not defined tags: - awx_config - name: "Update awx_credential_docker_registry_id" set_fact: awx_credential_docker_registry_id: "{{ awx_type_id }}" when: - awx_type_id != "None" 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: "dev-docker-registry-01.smardigo.digital/awx/awx-custom-ee" credential: "{{ awx_credential_docker_registry_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: "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 " shell: cd {{ playbook_dir }} && git archive --format tar.gz -o /tmp/hetzner-ansible.tar.gz HEAD delegate_to: 127.0.0.1 become: false tags: - awx_config - name: "Remove old rpository folder for " file: state: absent path: "{{ awx_project_path }}/hetzner-ansible" tags: - awx_config - name: "Create project folder for " file: path: "{{ awx_project_path }}/hetzner-ansible" state: directory owner: root group: root mode: '0555' tags: - awx_config - name: "Extract repository archive for " unarchive: src: /tmp/hetzner-ansible.tar.gz dest: "{{ awx_project_path }}/hetzner-ansible" tags: - awx_config - name: "Remove repository archive for " file: state: absent path: /tmp/hetzner-ansible.tar.gz 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: "Create job templates" include_tasks: awx-config-job-template.yml loop: - { name: "create-database-cluster", #description: "create-database-cluster", #playbook_file: "create-database-cluster.yml", credentials: [ "{{ awx_credential_hetzner_ansible_vault_id }}", "{{ awx_credential_hetzner_ansible_id }}", ] } - { name: "create-db-import", #description: "create-db-import", #playbook_file: "create-db-import.yml", credentials: [ "{{ awx_credential_hetzner_ansible_vault_id }}", "{{ awx_credential_hetzner_ansible_id }}", ] } - { name: "create-server", #description: "create-server", #playbook_file: "create-server.yml", credentials: [ "{{ awx_credential_hetzner_ansible_vault_id }}", "{{ awx_credential_hetzner_ansible_id }}", ] } - { name: "create-realm", #description: "create-realm", #playbook_file: "create-realm.yml", credentials: [ "{{ awx_credential_hetzner_ansible_vault_id }}", "{{ awx_credential_hetzner_ansible_id }}", ] } - { name: "create-service", #description: "create-service", #playbook_file: "create-service.yml", credentials: [ "{{ awx_credential_hetzner_ansible_vault_id }}", "{{ awx_credential_hetzner_ansible_id }}", ] } loop_control: loop_var: job tags: - awx_config