Структура команды

Структура команды#

Основу CLI контроллера составляет утилита awx, синтаксис вызова которой имеет следующий вид:

[<enviroments>] awx [<global-options>] <resource> <action> [<arguments>]
  • <enviroments> – переменные окружения:

    • CONTROLLER_HOST – URL контроллера.

    • CONTROLLER_VERIFY_SSL – параметры проверки сертификата TLS. Возможные значения:

      • true – строгая проверка сертификата;

      • false – проверка сертификата не выполняется.

    • CONTROLLER_USERNAME – название учетной записи пользователя контроллера.

    • CONTROLLER_PASSWORD – пароль пользователя контроллера.

    • CONTROLLER_OAUTH_TOKEN – токен пользователя контроллера.

    Примечание

    Переменные окружения и глобальные опции, указывающие одни и те же значения, не могут использоваться одновременно.

  • <global-options> – глобальные опции, которые могут применяться ко всем командам:

    • -h, --help#

      Информация о доступных опциях и командах.

    • -v, --verbose#

      Дополнительная информация о ходе выполнения команды.

    • -f, --conf.format#

      Формат вывода:

      • json – JSON;

      • jaml – YAML;

      • jq – формат, используемый утилитой jq;

      • human – вывод, удобный для чтения человеком.

    • --conf.host#

      URL контроллера.

    • -k, --conf.insecure#

      Разрешение небезопасного соединения с сервером при использовании сертификатов TLS.

    • --conf.username#

      Название учетной записи пользователя контроллера.

    • --conf.password#

      Пароль пользователя контроллера.

    • --conf.token#

      Токен пользователя контроллера.

  • <resource> – тип объекта или ресурса. Для получения полного списка объектов и ресурсов выполните команду:

    awx --help
    
  • <action> – действие, которое необходимо выполнить с объектом или ресурсом. Ресурсы и объекты, как правило, имеют базовый набор действий:

    • get – получение сведений об отдельном экземпляре;

    • list – получение списка экземпляров;

    • create – создание экземпляра;

    • modify – изменение свойств существующего экземпляра;

    • delete – удаление экземпляра.

    Чтобы узнать полный список доступных действий для конкретного объекта или ресурса, выполните команду:

    awx <resource> --help
    
  • <arguments> – дополнительные параметры, которые можно передать вместе с командой. Например, идентификатор инвентаря или проекта, название задания и другие.

Примеры использования CLI#

Вывод списка организаций:

awx organizations list -f human

Пример вывода команды:

id name
== ======================
1  Default

Вывод информации о необходимой организации:

awx organizations get <organizations_id>

Здесь <organizations_id> – идентификатор организации, например, 1.

Пример вывода команды:
{
  "id": 1,
  "type": "organization",
  "url": "/api/v2/organizations/1/",
  "summary_fields": {
    "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": 9,
        "user_only": true
      },
      "execute_role": {
        "description": "May run any executable resources in the organization",
        "name": "Execute",
        "id": 10
      },
      "project_admin_role": {
        "description": "Can manage all projects of the organization",
        "name": "Project Admin",
        "id": 11
      },
      "inventory_admin_role": {
        "description": "Can manage all inventories of the organization",
        "name": "Inventory Admin",
        "id": 12
      },
      "credential_admin_role": {
        "description": "Can manage all credentials of the organization",
        "name": "Credential Admin",
        "id": 13
      },
      "workflow_admin_role": {
        "description": "Can manage all workflows of the organization",
        "name": "Workflow Admin",
        "id": 14
      },
      "notification_admin_role": {
        "description": "Can manage all notifications of the organization",
        "name": "Notification Admin",
        "id": 15
      },
      "job_template_admin_role": {
        "description": "Can manage all job templates of the organization",
        "name": "Job Template Admin",
        "id": 16
      },
      "execution_environment_admin_role": {
        "description": "Can manage all execution environments of the organization",
        "name": "Execution Environment Admin",
        "id": 17
      },
      "auditor_role": {
        "description": "Can view all aspects of the organization",
        "name": "Auditor",
        "id": 18
      },
      "member_role": {
        "description": "User is a member of the organization",
        "name": "Member",
        "id": 19,
        "user_only": true
      },
      "read_role": {
        "description": "May view settings for the organization",
        "name": "Read",
        "id": 20
      },
      "approval_role": {
        "description": "Can approve or deny a workflow approval node",
        "name": "Approve",
        "id": 21
      }
    },
    "user_capabilities": {
      "edit": true,
      "delete": true
    },
    "related_field_counts": {
      "users": 2,
      "admins": 0,
      "inventories": 2,
      "teams": 3,
      "projects": 4,
      "job_templates": 2,
      "hosts": 2
    }
  },
  "created": "2024-02-16T00:06:02.349704Z",
  "modified": "2024-02-16T00:30:54.043146Z",
  "name": "Default",
  "description": "",
  "max_hosts": 0,
  "custom_virtualenv": null,
  "default_environment": null
}

Cоздание организации:

awx organizations create --name "<your_organization_name>"

Здесь <your_organization_name> – название организации, например, Saturn.

Пример вывода команды:
{
  "id": 4,
  "type": "organization",
  "url": "/api/v2/organizations/4/",
  "summary_fields": {
    "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": 171,
        "user_only": true
      },
      "execute_role": {
        "description": "May run any executable resources in the organization",
        "name": "Execute",
        "id": 172
      },
      "project_admin_role": {
        "description": "Can manage all projects of the organization",
        "name": "Project Admin",
        "id": 173
      },
      "inventory_admin_role": {
        "description": "Can manage all inventories of the organization",
        "name": "Inventory Admin",
        "id": 174
      },
      "credential_admin_role": {
        "description": "Can manage all credentials of the organization",
        "name": "Credential Admin",
        "id": 175
      },
      "workflow_admin_role": {
        "description": "Can manage all workflows of the organization",
        "name": "Workflow Admin",
        "id": 176
      },
      "notification_admin_role": {
        "description": "Can manage all notifications of the organization",
        "name": "Notification Admin",
        "id": 177
      },
      "job_template_admin_role": {
        "description": "Can manage all job templates of the organization",
        "name": "Job Template Admin",
        "id": 178
      },
      "execution_environment_admin_role": {
        "description": "Can manage all execution environments of the organization",
        "name": "Execution Environment Admin",
        "id": 179
      },
      "auditor_role": {
        "description": "Can view all aspects of the organization",
        "name": "Auditor",
        "id": 180
      },
      "member_role": {
        "description": "User is a member of the organization",
        "name": "Member",
        "id": 181,
        "user_only": true
      },
      "read_role": {
        "description": "May view settings for the organization",
        "name": "Read",
        "id": 182
      },
      "approval_role": {
        "description": "Can approve or deny a workflow approval node",
        "name": "Approve",
        "id": 183
      }
    },
    "user_capabilities": {
      "edit": true,
      "delete": true
    },
    "related_field_counts": {
      "inventories": 0,
      "teams": 0,
      "users": 0,
      "job_templates": 0,
      "admins": 0,
      "projects": 0
    }
  },
  "created": "2024-06-10T11:12:29.167911Z",
  "modified": "2024-06-10T11:12:29.167924Z",
  "name": "Saturn",
  "description": "",
  "max_hosts": 0,
  "custom_virtualenv": null,
  "default_environment": null
}

Изменение названия организации:

awx organizations modify <organization_id> --name "<new_name_organization>"

Здесь <new_name_organization> – новое название организации, например, Neptune.

Пример вывода команды:
{
  "id": 4,
  "type": "organization",
  "url": "/api/v2/organizations/4/",
  "summary_fields": {
    "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": 171,
        "user_only": true
      },
      "execute_role": {
        "description": "May run any executable resources in the organization",
        "name": "Execute",
        "id": 172
      },
      "project_admin_role": {
        "description": "Can manage all projects of the organization",
        "name": "Project Admin",
        "id": 173
      },
      "inventory_admin_role": {
        "description": "Can manage all inventories of the organization",
        "name": "Inventory Admin",
        "id": 174
      },
      "credential_admin_role": {
        "description": "Can manage all credentials of the organization",
        "name": "Credential Admin",
        "id": 175
      },
      "workflow_admin_role": {
        "description": "Can manage all workflows of the organization",
        "name": "Workflow Admin",
        "id": 176
      },
      "notification_admin_role": {
        "description": "Can manage all notifications of the organization",
        "name": "Notification Admin",
        "id": 177
      },
      "job_template_admin_role": {
        "description": "Can manage all job templates of the organization",
        "name": "Job Template Admin",
        "id": 178
      },
      "execution_environment_admin_role": {
        "description": "Can manage all execution environments of the organization",
        "name": "Execution Environment Admin",
        "id": 179
      },
      "auditor_role": {
        "description": "Can view all aspects of the organization",
        "name": "Auditor",
        "id": 180
      },
      "member_role": {
        "description": "User is a member of the organization",
        "name": "Member",
        "id": 181,
        "user_only": true
      },
      "read_role": {
        "description": "May view settings for the organization",
        "name": "Read",
        "id": 182
      },
      "approval_role": {
        "description": "Can approve or deny a workflow approval node",
        "name": "Approve",
        "id": 183
      }
    },
    "user_capabilities": {
      "edit": true,
      "delete": true
    },
    "related_field_counts": {
      "users": 0,
      "admins": 0,
      "inventories": 0,
      "teams": 0,
      "projects": 0,
      "job_templates": 0,
      "hosts": 0
    }
  },
  "created": "2024-06-10T11:12:29.167911Z",
  "modified": "2024-06-10T11:19:11.396969Z",
  "name": "Neptune",
  "description": "",
  "max_hosts": 0,
  "custom_virtualenv": null,
  "default_environment": null
}

Удаление организации:

awx organizations delete <organization_id>