Create an Azure Service Principal for Ansible Tower (AWX)
Scenario
You want to test Azure Provisioning using Ansible Tower (or the Open Source version, AWX) so you’ll need a way to authenticate with Azure.
Solution
An Azure Service Principle will need to be created so that Ansible Tower can authenticate.
Method 1: Azure CLI
- Install the Azure CLI.
- Create an Azure Service Principal called
ansible
with the passwordMyStrongPassw0rd!
az ad sp create-for-rbac --name ansible --password MyStrongPassw0rd!
- This will return some JSON like the example below:
{ "appId": "abcd1234-abcd-efff-1234-abcd12345678", "displayName": "ansible", "name": "http://ansible", "password": "MyStrongPassw0rd!", "tenant": "12345678-ab12-cd34-ef56-1234abcd5678" }
- The
appId
key above is referred to as theclient_id
for the Azure Credential in Ansible Tower. - The
password
key above is referred to as thesecret
for the Azure Credential in Ansible Tower. - The
tenant
key above is also referred to as thetenant
for the Azure Credential in Ansible Tower. - To show your Azure Subscriptions, run the following
> az account list --output table Name CloudName SubscriptionId State IsDefault ---------- ----------- ------------------------------------ ------- ----------- Free Trial AzureCloud aaaa1111-bbbb-cccc-abcd-aaabbbcccddd Enabled True
- Note down your
SubscriptionId
for later use.
Method 2: Azure PowerShell
- Install the new Azure PowerShell Module:
Install-Module -Name Az -AllowClobber
- Create an Azure Service Principal called
ansible
with the passwordMyStrongPassw0rd!
:$servicePrincipleName = 'ansible' $secureString = ConvertTo-SecureString 'MyStrongPassw0rd!' -AsPlainText -Force $azADApplicationParams = @{ DisplayName = $servicePrincipleName IdentifierUris = "http://$($servicePrincipleName)" Password = $secureString } New-AzADApplication @azADApplicationParams -Verbose
- This will return an object like this:
DisplayName : ansible ObjectId : 11111111-2222-3333-abcd-12345678abcd IdentifierUris : {http://ansible} HomePage : Type : ApplicationId : abcd1234-abcd-efff-1234-abcd12345678 AvailableToOtherTenants : False AppPermissions : ReplyUrls : {} ObjectType : Application
- The
ApplicationId
key above is referred to as theclient_id
for the Azure Credential in Ansible Tower. - To show your Azure Subscriptions, run the following
Get-AzSubscription Name Id TenantId State ---- -- -------- ----- Pay-As-You-Go aaaa1111-bbbb-cccc-abcd-aaabbbcccddd 12345678-ab12-cd34-ef56-1234abcd5678 Enabled
- Note down
Id
(Subscription ID) andTenantId
for later use.
Create an Azure Credential in Ansible Tower (AWX)
- Navigate to the Credentials page, within the Resources menu.
- Create a new Credential and ensure the
CREDENTIAL TYPE
field isMicrosoft Azure Resource Manager
. - Enter the previously created values into the
SUBSCRIPTION ID
,CLIENT ID
,CLIENT SECRET
, andTENANT ID
fields as shown below:
Leave a comment