Базовый сценарий#

В этом документе приведен базовый сценарий использования API Astra Automation Controller. В ходе выполнения сценария производятся следующие действия:

  1. Получение токена авторизации.

  2. Создание организации.

  3. Добавление полномочий Ansible Galaxy для созданной организации.

  4. Создание инвентаря.

  5. Добавление управляемого узла в инвентарь.

  6. Создание проекта.

  7. Создание шаблона задания для установки NGINX.

  8. Запуск шаблона задания.

  9. Проверка статуса выполнения задания.

Предварительные требования#

Перед выполнением сценария произведите следующие действия в графическом интерфейсе контроллера:

  1. Создайте полномочия для доступа к следующим ресурсам:

    • управляемый узел;

    • Ansible Galaxy;

    • Astra Automation Hub.

    Примечание

    С подробной информацией о работе с полномочиями можно ознакомиться в документе Полномочия.

  2. Получите идентификаторы созданных полномочий:

    1. На панели навигации выберите Ресурсы ‣ Полномочия (Resources ‣ Credentials).

    2. Нажмите на ссылку с названием нужного полномочия, например, Ansible Galaxy.

    3. Скопируйте <credentials_id> в адресной строке браузера, которая имеет следующий вид https://<address>/#/credentials/<credentials_id>/details.

Подготовка организационной структуры#

Для подготовки организационной структуры выполните следующие действия:

  1. Получите токен авторизации:

    curl -X POST \
       https://<address>/api/v2/tokens/ \
       -H 'Content-Type: application/json' \
       -d '{
                "description": "Token description",
                "application": null,
                "user": "<username>",
                "scope": "write"
           }' \
       -u '<username>:<password>' | jq .
    

    Подставьте собственные значения параметров вместо употребленных в примере:

    • <address> – FQDN или IP-адрес контроллера, например, 192.168.56.11;

    • <username> – имя пользователя, используемое для аутентификации в контроллере, например, admin;

    • <password> – пароль, например, awx.

    Эта команда возвращает JSON следующего вида:

    {
       "id": 13,
       "type": "o_auth2_access_token",
       "url": "/api/v2/tokens/13/",
       "related": {
          "user": "/api/v2/users/1/",
          "activity_stream": "/api/v2/tokens/13/activity_stream/"
       },
       "summary_fields": {
          "user": {
             "id": 1,
             "username": "admin",
             "first_name": "",
             "last_name": ""
          }
       },
       "created": "2024-03-21T08:38:43.412155Z",
       "modified": "2024-03-21T08:38:43.418814Z",
       "description": "Token description",
       "user": 1,
       "token": "<your_token>",
       "refresh_token": null,
       "application": null,
       "expires": "3023-07-23T08:38:43.406429Z",
       "scope": "write"
    }
    

    Здесь token – значение созданного токена. Сохраните его в надежном месте, оно понадобится позже.

  2. Получите идентификатор среды исполнения в графическом интерфейсе контроллера:

    1. На панели навигации выберите Администрирование ‣ Среды исполнения (Administration ‣ Execution Environments).

    2. Нажмите на ссылку с названием нужной среды исполнения, например, Default execution environment.

    3. Скопируйте <execution_environment_id> в адресной строке браузера, которая имеет следующий вид https://<address>/#/execution_environments/<execution_environments_id>/details.

  3. Создайте организацию:

    curl -X POST \
       -H 'Content-Type: application/json' \
       -H 'Authorization: Bearer <your_token>' \
       -d '{
                "name": "<your_organization_name>",
                "default_environment": "<execution_environment_id>"
           }' \
       https://<address>/api/v2/organizations/ | jq .
    

    Подставьте собственные значения параметров вместо употребленных в примере:

    • <your_token> – токен, полученный на предыдущем шаге, например, 3wijiG7********VtL2gseJESzjJsD;

    • <your_organization_name> – название организации, например, Jupiter;

    • <execution_environment_id> – идентификатор среды исполнения, например, 1.

    Organization
    {
      "id": 4,
      "type": "organization",
      "url": "/api/v2/organizations/4/",
      "related": {
        "named_url": "/api/v2/organizations/Jupiter/",
        "created_by": "/api/v2/users/1/",
        "modified_by": "/api/v2/users/1/",
        "execution_environments": "/api/v2/organizations/4/execution_environments/",
        "projects": "/api/v2/organizations/4/projects/",
        "inventories": "/api/v2/organizations/4/inventories/",
        "job_templates": "/api/v2/organizations/4/job_templates/",
        "workflow_job_templates": "/api/v2/organizations/4/workflow_job_templates/",
        "users": "/api/v2/organizations/4/users/",
        "admins": "/api/v2/organizations/4/admins/",
        "teams": "/api/v2/organizations/4/teams/",
        "credentials": "/api/v2/organizations/4/credentials/",
        "applications": "/api/v2/organizations/4/applications/",
        "activity_stream": "/api/v2/organizations/4/activity_stream/",
        "notification_templates": "/api/v2/organizations/4/notification_templates/",
        "notification_templates_started": "/api/v2/organizations/4/notification_templates_started/",
        "notification_templates_success": "/api/v2/organizations/4/notification_templates_success/",
        "notification_templates_error": "/api/v2/organizations/4/notification_templates_error/",
        "notification_templates_approvals": "/api/v2/organizations/4/notification_templates_approvals/",
        "object_roles": "/api/v2/organizations/4/object_roles/",
        "access_list": "/api/v2/organizations/4/access_list/",
        "instance_groups": "/api/v2/organizations/4/instance_groups/",
        "galaxy_credentials": "/api/v2/organizations/4/galaxy_credentials/",
        "default_environment": "/api/v2/execution_environments/1/"
      },
      "summary_fields": {
        "default_environment": {
          "id": 1,
          "name": "Default execution environment",
          "description": "",
          "image": "registry.astralinux.ru/aa/aa-base-ee:0.2.1"
        },
        "created_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "modified_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "object_roles": {
          "admin_role": {
            "description": "Can manage all aspects of the organization",
            "name": "Admin",
            "id": 103,
            "user_only": true
          },
          "execute_role": {
            "description": "May run any executable resources in the organization",
            "name": "Execute",
            "id": 104
          },
          "project_admin_role": {
            "description": "Can manage all projects of the organization",
            "name": "Project Admin",
            "id": 105
          },
          "inventory_admin_role": {
            "description": "Can manage all inventories of the organization",
            "name": "Inventory Admin",
            "id": 106
          },
          "credential_admin_role": {
            "description": "Can manage all credentials of the organization",
            "name": "Credential Admin",
            "id": 107
          },
          "workflow_admin_role": {
            "description": "Can manage all workflows of the organization",
            "name": "Workflow Admin",
            "id": 108
          },
          "notification_admin_role": {
            "description": "Can manage all notifications of the organization",
            "name": "Notification Admin",
            "id": 109
          },
          "job_template_admin_role": {
            "description": "Can manage all job templates of the organization",
            "name": "Job Template Admin",
            "id": 110
          },
          "execution_environment_admin_role": {
            "description": "Can manage all execution environments of the organization",
            "name": "Execution Environment Admin",
            "id": 111
          },
          "auditor_role": {
            "description": "Can view all aspects of the organization",
            "name": "Auditor",
            "id": 112
          },
          "member_role": {
            "description": "User is a member of the organization",
            "name": "Member",
            "id": 113,
            "user_only": true
          },
          "read_role": {
            "description": "May view settings for the organization",
            "name": "Read",
            "id": 114
          },
          "approval_role": {
            "description": "Can approve or deny a workflow approval node",
            "name": "Approve",
            "id": 115
          }
        },
        "user_capabilities": {
          "edit": true,
          "delete": true
        },
        "related_field_counts": {
          "inventories": 0,
          "teams": 0,
          "users": 0,
          "job_templates": 0,
          "admins": 0,
          "projects": 0
        }
      },
      "created": "2024-03-21T08:48:05.919683Z",
      "modified": "2024-03-21T08:48:05.919698Z",
      "name": "Jupiter",
      "max_hosts": 0,
      "custom_virtualenv": null,
      "default_environment": 1
    }
    
  4. Добавьте полномочия Ansible Galaxy для созданной организации:

    curl -X POST \
       -H 'Content-Type: application/json' \
       -H 'Authorization: Bearer <your_token>' \
       -d '{
                "id":<credentials_id>
           }' \
       https://<address>/api/v2/organizations/<organization_id>/galaxy_credentials/ | jq .
    

    Подставьте собственные значения параметров вместо употребленных в примере:

    • <credentials_id> – идентификатор полномочий для доступа к Ansible Galaxy, например, 2;

    • <organization_id> – идентификатор организации, созданной ранее, например, 4.

Подготовка инвентаря#

Для подготовки инвентаря выполните следующие действия:

  1. Создайте инвентарь:

    curl -X POST \
       -H 'Content-Type: application/json' \
       -H 'Authorization: Bearer <address>' \
       -d '{
                "name": "<your_inventory_name>",
                "organization": <organization_id>
           }' \
       https://<address>/api/v2/inventories/ | jq .
    

    Подставьте собственные значения параметров вместо употребленных в примере. Здесь <your_inventory_name> – название инвентаря, например, Demo Inventory.

    Inventory
    {
      "id": 4,
      "type": "inventory",
      "url": "/api/v2/inventories/4/",
      "related": {
        "named_url": "/api/v2/inventories/Demo Inventory++Jupiter/",
        "created_by": "/api/v2/users/1/",
        "modified_by": "/api/v2/users/1/",
        "hosts": "/api/v2/inventories/4/hosts/",
        "variable_data": "/api/v2/inventories/4/variable_data/",
        "script": "/api/v2/inventories/4/script/",
        "activity_stream": "/api/v2/inventories/4/activity_stream/",
        "job_templates": "/api/v2/inventories/4/job_templates/",
        "ad_hoc_commands": "/api/v2/inventories/4/ad_hoc_commands/",
        "access_list": "/api/v2/inventories/4/access_list/",
        "object_roles": "/api/v2/inventories/4/object_roles/",
        "instance_groups": "/api/v2/inventories/4/instance_groups/",
        "copy": "/api/v2/inventories/4/copy/",
        "labels": "/api/v2/inventories/4/labels/",
        "groups": "/api/v2/inventories/4/groups/",
        "root_groups": "/api/v2/inventories/4/root_groups/",
        "update_inventory_sources": "/api/v2/inventories/4/update_inventory_sources/",
        "inventory_sources": "/api/v2/inventories/4/inventory_sources/",
        "tree": "/api/v2/inventories/4/tree/",
        "organization": "/api/v2/organizations/4/"
      },
      "summary_fields": {
        "organization": {
          "id": 4,
          "name": "Jupiter"
        },
        "created_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "modified_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "object_roles": {
          "admin_role": {
            "description": "Can manage all aspects of the inventory",
            "name": "Admin",
            "id": 116
          },
          "update_role": {
            "description": "May update the inventory",
            "name": "Update",
            "id": 117
          },
          "adhoc_role": {
            "description": "May run ad hoc commands on the inventory",
            "name": "Ad Hoc",
            "id": 118
          },
          "use_role": {
            "description": "Can use the inventory in a job template",
            "name": "Use",
            "id": 119
          },
          "read_role": {
            "description": "May view settings for the inventory",
            "name": "Read",
            "id": 120
          }
        },
        "user_capabilities": {
          "edit": true,
          "delete": true,
          "copy": true,
          "adhoc": true
        },
        "labels": {
          "count": 0,
          "results": []
        }
      },
      "created": "2024-03-21T08:53:27.613062Z",
      "modified": "2024-03-21T08:53:27.613074Z",
      "name": "Jupiter",
      "organization": 4,
      "kind": "",
      "host_filter": null,
      "variables": "",
      "has_active_failures": false,
      "total_hosts": 0,
      "hosts_with_active_failures": 0,
      "total_groups": 0,
      "has_inventory_sources": false,
      "total_inventory_sources": 0,
      "inventory_sources_with_failures": 0,
      "pending_deletion": false,
      "prevent_instance_group_fallback": false
    }
    
  2. Добавьте управляемый узел в инвентарь:

    curl -X POST \
       -H 'Content-Type: application/json' \
       -H 'Authorization: Bearer <your_token>' \
       -d '{
                "name": "<node_ip>",
                "description": "<node_name>",
                "inventory": <inventory_id>,
                "enabled": true
           }' \
       https://<address>/api/v2/hosts/ | jq .
    

    Подставьте собственные значения параметров вместо употребленных в примере:

    • <node_ip> – IP-адрес управляемого узла например, 10.2.0.6;

    • <node_name> – название управляемого узла, например, node01;

    • <inventory_id> – идентификатор инвентаря, например, 4.

    Host
    {
      "id": 7,
      "type": "host",
      "url": "/api/v2/hosts/7/",
      "related": {
        "named_url": "/api/v2/hosts/10.2.0.6++Demo Inventory++Jupiter/",
        "created_by": "/api/v2/users/1/",
        "modified_by": "/api/v2/users/1/",
        "variable_data": "/api/v2/hosts/7/variable_data/",
        "groups": "/api/v2/hosts/7/groups/",
        "all_groups": "/api/v2/hosts/7/all_groups/",
        "job_events": "/api/v2/hosts/7/job_events/",
        "job_host_summaries": "/api/v2/hosts/7/job_host_summaries/",
        "activity_stream": "/api/v2/hosts/7/activity_stream/",
        "inventory_sources": "/api/v2/hosts/7/inventory_sources/",
        "smart_inventories": "/api/v2/hosts/7/smart_inventories/",
        "ad_hoc_commands": "/api/v2/hosts/7/ad_hoc_commands/",
        "ad_hoc_command_events": "/api/v2/hosts/7/ad_hoc_command_events/",
        "ansible_facts": "/api/v2/hosts/7/ansible_facts/",
        "inventory": "/api/v2/inventories/4/"
      },
      "summary_fields": {
        "inventory": {
          "id": 4,
          "name": "Demo Inventory",
          "has_active_failures": false,
          "total_hosts": 0,
          "hosts_with_active_failures": 0,
          "total_groups": 0,
          "has_inventory_sources": false,
          "total_inventory_sources": 0,
          "inventory_sources_with_failures": 0,
          "organization_id": 4,
          "kind": ""
        },
        "created_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "modified_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "user_capabilities": {
          "edit": true,
          "delete": true
        },
        "groups": {
          "count": 0,
          "results": []
        },
        "recent_jobs": []
      },
      "created": "2024-03-21T10:03:33.967091Z",
      "modified": "2024-03-21T10:03:33.967104Z",
      "name": "10.2.0.6",
      "description": "node01",
      "inventory": 4,
      "enabled": true,
      "instance_id": "",
      "variables": "",
      "has_active_failures": false,
      "has_inventory_sources": false,
      "last_job": null,
      "last_job_host_summary": null,
      "ansible_facts_modified": null
    }
    

Подготовка задания#

Для подготовки задания выполните следующие действия:

  1. Создайте проект:

    Примечание

    В качестве источника при создании проекта используется репозиторий с примерами с Astra Automation Hub.

    curl -X POST \
       -H 'Content-Type: application/json' \
       -H 'Authorization: Bearer <your_token>' \
       -d '{
                "name": "<your_project_name>",
                "scm_type": "git",
                "scm_url": "ssh://git@hub.astra-automation.ru:2222/aa-gca/AA/aac-samples.git",
                "scm_branch": "master",
                "default_environment": <environment_id>,
                "credential": <credential_id>,
                "organization": <organization_id>
           }' \
       https://<address>/api/v2/projects/ | jq .
    

    Подставьте собственные значения параметров вместо употребленных в примере:

    • <your_project_name> – название проекта, например, Demo NGINX Project;

    • <credentials_id> – идентификатор полномочий для доступа к Astra Automation Hub, например, 3.

    Project
    {
      "id": 14,
      "type": "project",
      "url": "/api/v2/projects/14/",
      "related": {
        "named_url": "/api/v2/projects/Demo NGINX Project++Jupiter/",
        "created_by": "/api/v2/users/1/",
        "modified_by": "/api/v2/users/1/",
        "credential": "/api/v2/credentials/3/",
        "current_job": "/api/v2/project_updates/9/",
        "teams": "/api/v2/projects/14/teams/",
        "playbooks": "/api/v2/projects/14/playbooks/",
        "inventory_files": "/api/v2/projects/14/inventories/",
        "update": "/api/v2/projects/14/update/",
        "project_updates": "/api/v2/projects/14/project_updates/",
        "scm_inventory_sources": "/api/v2/projects/14/scm_inventory_sources/",
        "schedules": "/api/v2/projects/14/schedules/",
        "activity_stream": "/api/v2/projects/14/activity_stream/",
        "notification_templates_started": "/api/v2/projects/14/notification_templates_started/",
        "notification_templates_success": "/api/v2/projects/14/notification_templates_success/",
        "notification_templates_error": "/api/v2/projects/14/notification_templates_error/",
        "access_list": "/api/v2/projects/14/access_list/",
        "object_roles": "/api/v2/projects/14/object_roles/",
        "copy": "/api/v2/projects/14/copy/",
        "organization": "/api/v2/organizations/4/",
        "default_environment": "/api/v2/execution_environments/1/",
        "current_update": "/api/v2/project_updates/9/"
      },
      "summary_fields": {
        "organization": {
          "id": 4,
          "name": "Jupiter"
        },
        "default_environment": {
          "id": 1,
          "name": "Default execution environment",
          "description": "",
          "image": "registry.astralinux.ru/aa/aa-base-ee:0.2.1"
        },
        "credential": {
          "id": 3,
          "name": "Credentials for AA Hub",
          "description": "",
          "kind": "scm",
          "cloud": false,
          "kubernetes": false,
          "credential_type_id": 2
        },
        "current_update": {
          "id": 9,
          "name": "Demo NGINX Project",
          "status": "pending",
          "failed": false
        },
        "current_job": {
          "id": 9,
          "name": "Demo NGINX Project",
          "status": "pending",
          "failed": false
        },
        "created_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "modified_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "object_roles": {
          "admin_role": {
            "description": "Can manage all aspects of the project",
            "name": "Admin",
            "id": 134
          },
          "use_role": {
            "description": "Can use the project in a job template",
            "name": "Use",
            "id": 135
          },
          "update_role": {
            "description": "May update the project",
            "name": "Update",
            "id": 136
          },
          "read_role": {
            "description": "May view settings for the project",
            "name": "Read",
            "id": 137
          }
        },
        "user_capabilities": {
          "edit": true,
          "delete": true,
          "start": true,
          "schedule": true,
          "copy": true
        }
      },
      "created": "2024-03-21T09:44:26.824017Z",
      "modified": "2024-03-21T09:44:26.824031Z",
      "name": "Demo NGINX Project",
      "local_path": "_14__demo_nginx_project",
      "scm_type": "git",
      "scm_url": "ssh://git@hub.astra-automation.ru:2222/aa-gca/AA/aac-samples.git",
      "scm_branch": "master",
      "scm_refspec": "",
      "scm_clean": false,
      "scm_track_submodules": false,
      "scm_delete_on_update": false,
      "credential": 3,
      "timeout": 0,
      "scm_revision": "",
      "last_job_run": null,
      "last_job_failed": false,
      "next_job_run": null,
      "status": "pending",
      "organization": 4,
      "scm_update_on_launch": false,
      "scm_update_cache_timeout": 0,
      "allow_override": false,
      "custom_virtualenv": null,
      "default_environment": 1,
      "signature_validation_credential": null,
      "last_update_failed": false,
      "last_updated": null
    }
    
  2. Создайте шаблон задания для установки NGINX:

    curl -X POST \
       -H 'Content-Type: application/json' \
       -H 'Authorization: Bearer <your_token>' \
       -d '{
                "name": "NGINX Deployment",
                "job_type": "run",
                "inventory": <inventory_id>,
                "project": <project_id>,
                "playbook": "nginx/site.yml"
           }' \
       https://<address>/api/v2/job_templates/ | jq .
    

    Подставьте собственные значения параметров вместо употребленных в примере. Здесь <project_id> – идентификатор проекта, созданного ранее, например, 14.

    Job template
    {
      "id": 15,
      "type": "job_template",
      "url": "/api/v2/job_templates/15/",
      "related": {
        "named_url": "/api/v2/job_templates/NGINX Deployment++Jupiter/",
        "created_by": "/api/v2/users/1/",
        "modified_by": "/api/v2/users/1/",
        "labels": "/api/v2/job_templates/15/labels/",
        "inventory": "/api/v2/inventories/4/",
        "project": "/api/v2/projects/14/",
        "organization": "/api/v2/organizations/4/",
        "credentials": "/api/v2/job_templates/15/credentials/",
        "jobs": "/api/v2/job_templates/15/jobs/",
        "schedules": "/api/v2/job_templates/15/schedules/",
        "activity_stream": "/api/v2/job_templates/15/activity_stream/",
        "launch": "/api/v2/job_templates/15/launch/",
        "webhook_key": "/api/v2/job_templates/15/webhook_key/",
        "webhook_receiver": "",
        "notification_templates_started": "/api/v2/job_templates/15/notification_templates_started/",
        "notification_templates_success": "/api/v2/job_templates/15/notification_templates_success/",
        "notification_templates_error": "/api/v2/job_templates/15/notification_templates_error/",
        "access_list": "/api/v2/job_templates/15/access_list/",
        "survey_spec": "/api/v2/job_templates/15/survey_spec/",
        "object_roles": "/api/v2/job_templates/15/object_roles/",
        "instance_groups": "/api/v2/job_templates/15/instance_groups/",
        "slice_workflow_jobs": "/api/v2/job_templates/15/slice_workflow_jobs/",
        "copy": "/api/v2/job_templates/15/copy/"
      },
      "summary_fields": {
        "organization": {
          "id": 4,
          "name": "Jupiter"
        },
        "inventory": {
          "id": 4,
          "name": "Demo Inventory",
          "has_active_failures": false,
          "total_hosts": 0,
          "hosts_with_active_failures": 0,
          "total_groups": 0,
          "has_inventory_sources": false,
          "total_inventory_sources": 0,
          "inventory_sources_with_failures": 0,
          "organization_id": 4,
          "kind": ""
        },
        "project": {
          "id": 14,
          "name": "Demo NGINX Project",
          "status": "successful",
          "scm_type": "git",
          "allow_override": false
        },
        "created_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "modified_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "object_roles": {
          "admin_role": {
            "description": "Can manage all aspects of the job template",
            "name": "Admin",
            "id": 138
          },
          "execute_role": {
            "description": "May run the job template",
            "name": "Execute",
            "id": 139
          },
          "read_role": {
            "description": "May view settings for the job template",
            "name": "Read",
            "id": 140
          }
        },
        "user_capabilities": {
          "edit": true,
          "delete": true,
          "start": true,
          "schedule": true,
          "copy": true
        },
        "labels": {
          "count": 0,
          "results": []
        },
        "recent_jobs": [],
        "credentials": []
      },
      "created": "2024-03-21T09:52:41.673531Z",
      "modified": "2024-03-21T09:52:41.673545Z",
      "name": "NGINX Deployment",
      "description": "",
      "job_type": "run",
      "inventory": 4,
      "project": 14,
      "playbook": "nginx/site.yml",
      "scm_branch": "",
      "forks": 0,
      "limit": "",
      "verbosity": 0,
      "extra_vars": "",
      "job_tags": "",
      "force_handlers": false,
      "skip_tags": "",
      "start_at_task": "",
      "timeout": 0,
      "use_fact_cache": false,
      "organization": 4,
      "last_job_run": null,
      "last_job_failed": false,
      "next_job_run": null,
      "status": "never updated",
      "execution_environment": null,
      "host_config_key": "",
      "ask_scm_branch_on_launch": false,
      "ask_diff_mode_on_launch": false,
      "ask_variables_on_launch": false,
      "ask_limit_on_launch": false,
      "ask_tags_on_launch": false,
      "ask_skip_tags_on_launch": false,
      "ask_job_type_on_launch": false,
      "ask_verbosity_on_launch": false,
      "ask_inventory_on_launch": false,
      "ask_credential_on_launch": false,
      "ask_execution_environment_on_launch": false,
      "ask_labels_on_launch": false,
      "ask_forks_on_launch": false,
      "ask_job_slice_count_on_launch": false,
      "ask_timeout_on_launch": false,
      "ask_instance_groups_on_launch": false,
      "survey_enabled": false,
      "become_enabled": false,
      "diff_mode": false,
      "allow_simultaneous": false,
      "custom_virtualenv": null,
      "job_slice_count": 1,
      "webhook_service": "",
      "webhook_credential": null,
      "prevent_instance_group_fallback": false
    }
    
  3. Добавьте полномочия для шаблона задания:

    curl -X POST \
       -H 'Content-Type: application/json' \
       -H 'Authorization: Bearer <your_token>' \
       -d '{
                "id":<credential_id>
           }' \
       https://<address>/api/v2/job_templates/<job_template_id>/credentials/ | jq .
    

    Подставьте собственные значения параметров вместо употребленных в примере:

    • <credentials_id> – идентификатор полномочий для доступа к управляемому узлу, например, 1;

    • <job_template_id> – идентификатор созданного ранее шаблона задания, например, 15.

Выполнение и проверка задания#

Для запуска и проверки статуса задания выполните следующие действия:

  1. Запустите задание, используя созданный шаблон:

    curl -X POST \
       -H 'Authorization: Bearer <your_token>' \
       https://<address>/api/v2/job_templates/<job_template_id>/launch/ | jq .
    
    Job template
    {
      "job": 10,
      "ignored_fields": {},
      "id": 10,
      "type": "job",
      "url": "/api/v2/jobs/10/",
      "related": {
        "created_by": "/api/v2/users/1/",
        "modified_by": "/api/v2/users/1/",
        "labels": "/api/v2/jobs/10/labels/",
        "inventory": "/api/v2/inventories/4/",
        "project": "/api/v2/projects/14/",
        "organization": "/api/v2/organizations/4/",
        "credentials": "/api/v2/jobs/10/credentials/",
        "unified_job_template": "/api/v2/job_templates/15/",
        "stdout": "/api/v2/jobs/10/stdout/",
        "job_events": "/api/v2/jobs/10/job_events/",
        "job_host_summaries": "/api/v2/jobs/10/job_host_summaries/",
        "activity_stream": "/api/v2/jobs/10/activity_stream/",
        "notifications": "/api/v2/jobs/10/notifications/",
        "create_schedule": "/api/v2/jobs/10/create_schedule/",
        "job_template": "/api/v2/job_templates/15/",
        "cancel": "/api/v2/jobs/10/cancel/",
        "relaunch": "/api/v2/jobs/10/relaunch/"
      },
      "summary_fields": {
        "organization": {
          "id": 4,
          "name": "Jupiter"
        },
        "inventory": {
          "id": 4,
          "name": "Demo Inventory",
          "has_active_failures": false,
          "total_hosts": 0,
          "hosts_with_active_failures": 0,
          "total_groups": 0,
          "has_inventory_sources": false,
          "total_inventory_sources": 0,
          "inventory_sources_with_failures": 0,
          "organization_id": 4,
          "kind": ""
        },
        "project": {
          "id": 14,
          "name": "Demo NGINX Project",
          "status": "successful",
          "scm_type": "git",
          "allow_override": false
        },
        "job_template": {
          "id": 15,
          "name": "NGINX Deployment",
          "description": ""
        },
        "unified_job_template": {
          "id": 15,
          "name": "NGINX Deployment",
          "description": "",
          "unified_job_type": "job"
        },
        "created_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "modified_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "user_capabilities": {
          "delete": true,
          "start": true
        },
        "labels": {
          "count": 0,
          "results": []
        },
        "credentials": [
          {
            "id": 4,
            "name": "NGINX Machine Credential",
            "description": "",
            "kind": "ssh",
            "cloud": false
          }
        ]
      },
      "created": "2024-03-21T10:02:14.206401Z",
      "modified": "2024-03-21T10:02:14.230669Z",
      "name": "NGINX Deployment",
      "description": "",
      "job_type": "run",
      "inventory": 4,
      "project": 14,
      "playbook": "nginx/site.yml",
      "scm_branch": "",
      "forks": 0,
      "limit": "",
      "verbosity": 0,
      "extra_vars": "{}",
      "job_tags": "",
      "force_handlers": false,
      "skip_tags": "",
      "start_at_task": "",
      "timeout": 0,
      "use_fact_cache": false,
      "organization": 4,
      "unified_job_template": 15,
      "launch_type": "manual",
      "status": "pending",
      "execution_environment": null,
      "failed": false,
      "started": null,
      "finished": null,
      "canceled_on": null,
      "elapsed": 0,
      "job_args": "",
      "job_cwd": "",
      "job_env": {},
      "job_explanation": "",
      "execution_node": "",
      "controller_node": "",
      "result_traceback": "",
      "event_processing_finished": false,
      "launched_by": {
        "id": 1,
        "name": "admin",
        "type": "user",
        "url": "/api/v2/users/1/"
      },
      "work_unit_id": null,
      "job_template": 15,
      "passwords_needed_to_start": [],
      "allow_simultaneous": false,
      "artifacts": {},
      "scm_revision": "",
      "instance_group": null,
      "diff_mode": false,
      "job_slice_number": 0,
      "job_slice_count": 1,
      "webhook_service": "",
      "webhook_credential": null,
      "webhook_guid": ""
    }
    
  2. Проверьте статус выполнения задания:

    curl -X GET \
       https://<address>/api/v2/jobs/<id_job>/ \
       -H 'Authorization: Bearer <your_token>' \
       -k -s | jq .
    

    Подставьте собственные значения параметров вместо употребленных в примере. Здесь <id_job> – идентификатор задания, запущенного ранее, например, 11.

    Job
    {
      "id": 11,
      "type": "job",
      "url": "/api/v2/jobs/11/",
      "related": {
        "created_by": "/api/v2/users/1/",
        "labels": "/api/v2/jobs/11/labels/",
        "inventory": "/api/v2/inventories/4/",
        "project": "/api/v2/projects/14/",
        "organization": "/api/v2/organizations/4/",
        "credentials": "/api/v2/jobs/11/credentials/",
        "unified_job_template": "/api/v2/job_templates/15/",
        "stdout": "/api/v2/jobs/11/stdout/",
        "execution_environment": "/api/v2/execution_environments/1/",
        "job_events": "/api/v2/jobs/11/job_events/",
        "job_host_summaries": "/api/v2/jobs/11/job_host_summaries/",
        "activity_stream": "/api/v2/jobs/11/activity_stream/",
        "notifications": "/api/v2/jobs/11/notifications/",
        "create_schedule": "/api/v2/jobs/11/create_schedule/",
        "job_template": "/api/v2/job_templates/15/",
        "cancel": "/api/v2/jobs/11/cancel/",
        "relaunch": "/api/v2/jobs/11/relaunch/"
      },
      "summary_fields": {
        "organization": {
          "id": 4,
          "name": "Jupiter"
        },
        "inventory": {
          "id": 4,
          "name": "Demo Inventory",
          "has_active_failures": false,
          "total_hosts": 1,
          "hosts_with_active_failures": 0,
          "total_groups": 0,
          "has_inventory_sources": false,
          "total_inventory_sources": 0,
          "inventory_sources_with_failures": 0,
          "organization_id": 4,
          "kind": ""
        },
        "execution_environment": {
          "id": 1,
          "name": "Default execution environment",
          "description": "",
          "image": "registry.astralinux.ru/aa/aa-base-ee:0.2.1"
        },
        "project": {
          "id": 14,
          "name": "Demo NGINX Project",
          "status": "successful",
          "scm_type": "git",
          "allow_override": false
        },
        "job_template": {
          "id": 15,
          "name": "NGINX Deployment",
          "description": ""
        },
        "unified_job_template": {
          "id": 15,
          "name": "NGINX Deployment",
          "description": "",
          "unified_job_type": "job"
        },
        "instance_group": {
          "id": 2,
          "name": "default",
          "is_container_group": false
        },
        "created_by": {
          "id": 1,
          "username": "admin",
          "first_name": "",
          "last_name": ""
        },
        "user_capabilities": {
          "delete": true,
          "start": true
        },
        "labels": {
          "count": 0,
          "results": []
        },
        "credentials": [
          {
            "id": 4,
            "name": "NGINX Machine Credentials",
            "description": "",
            "kind": "ssh",
            "cloud": false
          }
        ]
      },
      "created": "2024-03-21T10:03:39.307771Z",
      "modified": "2024-03-21T10:03:39.534635Z",
      "name": "NGINX Deployment",
      "description": "",
      "job_type": "run",
      "inventory": 4,
      "project": 14,
      "playbook": "nginx/site.yml",
      "scm_branch": "",
      "forks": 0,
      "limit": "",
      "verbosity": 0,
      "extra_vars": "{}",
      "job_tags": "",
      "force_handlers": false,
      "skip_tags": "",
      "start_at_task": "",
      "timeout": 0,
      "use_fact_cache": false,
      "organization": 4,
      "unified_job_template": 15,
      "launch_type": "manual",
      "status": "successful",
      "execution_environment": 1,
      "failed": false,
      "started": "2024-03-21T10:03:39.605438Z",
      "finished": "2024-03-21T10:03:49.709550Z",
      "canceled_on": null,
      "elapsed": 10.104,
      "job_args": "[\"podman\", \"run\", \"--rm\", \"--tty\", \"--interactive\", \"--workdir\", \"/runner/project\", \"-v\", \"/tmp/awx_11_9_5zjzyv/:/runner/:Z\", \"--env-file\", \"/tmp/awx_11_9_5zjzyv/artifacts/11/env.list\", \"--quiet\", \"--name\", \"ansible_runner_11\", \"--user=root\", \"--network\", \"slirp4netns:enable_ipv6=true\", \"registry.astralinux.ru/aa/aa-base-ee:0.2.1\", \"ssh-agent\", \"sh\", \"-c\", \"trap 'rm -f /runner/artifacts/11/ssh_key_data' EXIT && ssh-add /runner/artifacts/11/ssh_key_data && rm -f /runner/artifacts/11/ssh_key_data && ansible-playbook -u astra -i /runner/inventory/hosts -e @/runner/env/extravars nginx/site.yml\"]",
      "job_cwd": "/runner/project",
      "job_env": {
        "ANSIBLE_UNSAFE_WRITES": "1",
        "AWX_ISOLATED_DATA_DIR": "/runner/artifacts/11",
        "ANSIBLE_FORCE_COLOR": "True",
        "ANSIBLE_HOST_KEY_CHECKING": "False",
        "ANSIBLE_INVENTORY_UNPARSED_FAILED": "True",
        "ANSIBLE_PARAMIKO_RECORD_HOST_KEYS": "False",
        "HOME": "/var/lib/awx",
        "AWX_PRIVATE_DATA_DIR": "/tmp/awx_11_9_5zjzyv",
        "JOB_ID": "11",
        "INVENTORY_ID": "4",
        "PROJECT_REVISION": "d7f0ff18cf8ffb44d64e8acd995402d545e2de90",
        "ANSIBLE_RETRY_FILES_ENABLED": "False",
        "MAX_EVENT_RES": "700000",
        "AWX_HOST": "https://controller",
        "ANSIBLE_SSH_CONTROL_PATH_DIR": "/runner/cp",
        "ANSIBLE_COLLECTIONS_PATHS": "/runner/requirements_collections:~/.ansible/collections:/usr/share/ansible/collections",
        "ANSIBLE_ROLES_PATH": "/runner/requirements_roles:~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles",
        "ANSIBLE_CALLBACK_PLUGINS": "/runner/artifacts/11/callback",
        "ANSIBLE_STDOUT_CALLBACK": "awx_display",
        "RUNNER_OMIT_EVENTS": "False",
        "RUNNER_ONLY_FAILED_EVENTS": "False"
      },
      "job_explanation": "",
      "execution_node": "10.2.0.5",
      "controller_node": "10.2.0.5",
      "result_traceback": "",
      "event_processing_finished": true,
      "launched_by": {
        "id": 1,
        "name": "admin",
        "type": "user",
        "url": "/api/v2/users/1/"
      },
      "work_unit_id": "EQMxvG0G",
      "job_template": 15,
      "passwords_needed_to_start": [],
      "allow_simultaneous": false,
      "artifacts": {},
      "scm_revision": "d7f0ff18cf8ffb44d64e8acd995402d545e2de90",
      "instance_group": 2,
      "diff_mode": false,
      "job_slice_number": 0,
      "job_slice_count": 1,
      "webhook_service": "",
      "webhook_credential": null,
      "webhook_guid": "",
      "host_status_counts": {
        "ok": 1
      },
      "playbook_counts": {
        "play_count": 1,
        "task_count": 16
      },
      "custom_virtualenv": null
    }
    

    Если в поле failed указано значение false, значит задание завершилось успешно.