> For the complete documentation index, see [llms.txt](https://docs.realmjoin.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.realmjoin.com/pt/automacao/connecting-azure-automation.md).

# Ligar ao Azure Automation

## Visão geral

{% embed url="<https://www.youtube.com/watch?v=Ijp9XnE8UuA>" %}

Para permitir que o RealmJoin Portal forneça [runbooks ](/pt/automacao/runbooks.md)para automatizar tarefas diárias, você deve conectar uma [Azure Automation](https://learn.microsoft.com/en-us/azure/automation/overview) Conta. Esta Conta de Automação atuará como o host dos seus runbooks e fornecerá as [permissões](/pt/automacao/connecting-azure-automation/azure-ad-roles-and-permissions.md) necessárias para que os runbooks funcionem no seu ambiente.

## Considerações

Da Conta de Automação [Managed Identity](https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview) requer amplos [permissões ](/pt/automacao/connecting-azure-automation/azure-ad-roles-and-permissions.md)em seu ambiente, como a capacidade de modificar objetos de grupo ou de usuário no Entra ID ou gerenciar caixas de correio no Exchange Online. Limite o acesso administrativo a esta conta para evitar o uso indevido desses privilégios.

Ao usar uma Conta de Automação existente, observe que o RealmJoin Portal cria, atualiza e remove automaticamente runbooks provenientes do [repositório online compartilhado de runbooks](https://github.com/realmjoin/realmjoin-runbooks). Essa funcionalidade pode não ser suportada em uma Conta de Automação existente. Se não tiver certeza, recomendamos criar uma Conta dedicada do Azure Automation para RealmJoin Runbooks.

## Pré-requisitos

* privilégios de Administrador Global
* Acesso ao PowerShell com o [Az](https://learn.microsoft.com/en-us/powershell/azure/?view=azps-15.3.0) módulo ou [AZ CLI](https://learn.microsoft.com/en-us/cli/azure/?view=azure-cli-latest)
* permissões de Contribuidor em uma assinatura do Azure
* [Requisitos do runbook](/pt/automacao/connecting-azure-automation/azure-ad-roles-and-permissions.md)

## Instruções

{% stepper %}
{% step %}

#### Criar uma Conta do Azure Automation

1. Acesse o seu [Azure Portal > Automation Accounts](https://portal.azure.com/#create/Microsoft.AutomationAccount)
2. Crie uma nova Conta de Automação
3. Na guia Básicos, escolha a Assinatura, Grupo de Recursos, Nome da Conta de Automação e Região desejados<br>

   <figure><img src="/files/dcf07a797e97ef02fee4544ad0371151a22670f8" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
É recomendado um Grupo de Recursos separado para a sua Conta de Automação
{% endhint %}

4. Na guia Avançado, verifique se a System Assigned Managed Identity está habilitada

   <figure><img src="/files/bb2cf09cfa9c6f3735eeb77db0c02cb5212e6bf5" alt=""><figcaption></figcaption></figure>
5. Selecione Revisar + Criar e crie sua Conta de Automação
6. Acesse o Grupo de Recursos que contém sua Conta do Azure Automation
7. Na guia IAM, atribua à Conta do Azure Automation a função de Contribuidor
   {% endstep %}

{% step %}

#### Atribuir permissões à Conta do Azure Automation

Os runbooks compartilhados do RealmJoin usam a identidade gerenciada atribuída pelo sistema do Azure Automation para interagir com Entra ID, MS Graph API etc.

As permissões de Managed Identity não podem, atualmente, ser concedidas por meio do Azure Portal. Use Microsoft Graph ou PowerShell para atribuir essas permissões.

1. Baixe os seguintes scripts do PowerShell e arquivos JSON para a mesma pasta.\
   O script atribuirá o conjunto completo de permissões exigido pelo RealmJoin. As funções e permissões podem ser revisadas na [Requisitos](/pt/automacao/connecting-azure-automation/azure-ad-roles-and-permissions.md) seção e ajustadas conforme necessário nos arquivos JSON.

{% tabs %}
{% tab title="GrantAppPermToEntApp.ps1" %}
{% @github-files/github-code-block url="<https://github.com/Workplace-Foundation/approle-and-directoryrole-granter/blob/main/GrantAppPermToEntApp.ps1>" %}
{% endtab %}

{% tab title="AssignAzureADRoleToEntApp.ps1" %}
{% @github-files/github-code-block url="<https://github.com/Workplace-Foundation/approle-and-directoryrole-granter/blob/main/AssignAzureADRoleToEntApp.ps1>" %}
{% endtab %}

{% tab title="AllRealmJoinRunbooks\_collected\_permissions.json" %}
{% @github-files/github-code-block url="<https://github.com/realmjoin/realmjoin-runbooks/blob/production/docs/other/json/AllRealmJoinRunbooks_collected_permissions.json>" %}
{% endtab %}

{% tab title="AllRealmJoinRunbooks\_collected\_rbacroles.json" %}
{% @github-files/github-code-block url="<https://github.com/realmjoin/realmjoin-runbooks/blob/production/docs/other/json/AllRealmJoinRunbooks_collected_rbacroles.json>" %}
{% endtab %}
{% endtabs %}

2. Anote o Object ID da Managed Identity da Conta do Azure Automation em Account Settings > Identity

   <figure><img src="/files/49e47a0e1ed67d5b48b0ac46cfbd546f756c1b7d" alt=""><figcaption></figcaption></figure>
3. Abra uma janela do PowerShell.
4. Acesse a pasta que contém os arquivos baixados

```
cd c:\temp\myfolder
```

5. Desbloqueie os scripts, se necessário\
   ![](/files/844f2e6d7875fa327ee483b47d643b9f9681eac6)
6. Atribua permissões do MS Graph à sua Conta do Azure Automation usando GrantAppPermToEntApp.ps1, substituindo xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx pelo Object ID da sua Conta de Automação

```
. .\GrantAppPermToEntApp.ps1 -enterpriseAppObjId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -permissionsTemplate .\AllRealmJoinRunbooks_collected_permissions.json
```

7. Atribua funções de administrador do Entra ID à sua Conta do Azure Automation usando AssignAzureADRoleToEntApp.ps1, substituindo xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx pelo Object ID da sua Conta de Automação

```
. .\AssignAzureADRoleToEntApp.ps1 -objectId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" -rolesTemplate .\AllRealmJoinRunbooks_collected_rbacroles.json
```

8. A Conta do Azure Automation agora deve ter as permissões corretas para executar runbooks<br>
   {% endstep %}

{% step %}

#### Configuração de Runbook do RealmJoin - Parte 1

1. No RealmJoin Portal, vá para '[Configurações -> Runbooks](https://portal.realmjoin.com/settings/runbooks-configuration)'.<br>

   <figure><img src="/files/2a1943415b9acdeea0f25e441aefda87769f7c9c" alt=""><figcaption></figcaption></figure>
2. Preencha o Tenant ID, Subscription ID e o nome do Resource Group pertencentes à Conta do Azure Automation\
   O Tenant ID na [página de visão geral do Entra ID](https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/Overview)

   <figure><img src="/files/e6a1f453d012e1059ce1f6420f534bfb927ff923" alt=""><figcaption></figcaption></figure>
3. Copie o script em vermelho abaixo *ResourceGroup.*\
   Este script cria um Service Principal no Entra ID com acesso à sua Conta de Automação, permitindo que o RealmJoin gerencie, execute e monitore runbooks.\
   O script é atualizado com base nas entradas para Tenant ID, Subscription ID e Resource Group.<br>

   <figure><img src="/files/ee55479b4f96cd2bbe2f25b23a3860209c29b691" alt=""><figcaption></figcaption></figure>
4. Deixe o assistente aberto por enquanto. Voltaremos em breve na parte 2.
   {% endstep %}

{% step %}

#### Concedendo acesso do RealmJoin ao Azure Automation

{% hint style="info" %}
Você pode usar [Azure CloudShell](https://docs.microsoft.com/en-us/azure/cloud-shell/overview), portanto não é necessário instalar e autenticar uma cópia local do AZ CLI.
{% endhint %}

1. Execute no PowerShell o script copiado anteriormente.

   <figure><img src="/files/0d47dd7513fe4efa4d0e717bde43e7024413b092" alt=""><figcaption></figcaption></figure>
2. Anote os valores de `appId` e `password`.\
   O registro de aplicativo "RealmJoin Runbook Management" será criado.<br>

   ![Registros de aplicativos no Azure Portal](/files/4e5b78c840632aee87946ca1c047a6c5da9e431e)
   {% endstep %}

{% step %}

#### Configuração de Runbook do RealmJoin - Parte 2

1. No RealmJoin Portal, volte para a janela/assistente aberto para '[Configurações -> Runbooks](https://portal.realmjoin.com/settings/runbooks-configuration)'
2. Preencha os valores ausentes de `appId` e `password` criado na etapa anterior
3. Preencha o nome da Conta de Automação criada [anteriormente](#create-an-azure-automation-account)
4. Escolha a Branch do repositório compartilhado de runbooks que você deseja seguir.\
   Se não tiver certeza, escolha `produção`\
   Todos os branches de runbooks podem ser vistos aqui: <https://github.com/realmjoin/realmjoin-runbooks>
5. Escolha a mesma localização da sua Conta do Azure Automation para garantir que seus runbooks sejam executados na [região do Azure](https://docs.microsoft.com/en-us/azure/availability-zones/az-overview)

![Conexão da Conta de Automação no RealmJoin Portal](/files/93efa49e0f381e1938d0a03932d79f34c18c2ae6)

6. Pressione "Save" para iniciar a importação inicial dos runbooks. Por favor, deixe esta janela aberta até ver a mensagem "Sync completed".

![](/files/959b02e32fff69fb2f857fe116a95b90ac079669)
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.realmjoin.com/pt/automacao/connecting-azure-automation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
