Giter VIP home page Giter VIP logo

ansible-azure-samples's Introduction

ansible-on-azure

Sample Ansible playbooks for deploying and managing Azure resources.

Prerequisites

1. Create an Azure AD Service Principal

PowerShell

  1. Create the Azure AD Service Principal Account

    $password = '<Password>'
    
    $credentials = New-Object Microsoft.Azure.Commands.ActiveDirectory.PSADPasswordCredential `
    -Property @{ StartDate=Get-Date; EndDate=Get-Date -Year 2024; Password=$password}
    
    $spSplat = @{
      DisplayName = 'ansible'
      PasswordCredential = $credentials
    }
    
    $sp = New-AzAdServicePrincipal @spSplat

    Replace <Password> with your password.

  2. Assign the Contributor Role to the Service Principal

    $subId = (Get-AzContext).Subscription.Id
    
    $roleAssignmentSplat = @{
      ObjectId = $sp.id;
      RoleDefinitionName = 'Contributor';
      Scope = "/subscriptions/$subId"
    }
    
    New-AzRoleAssignment @roleAssignmentSplat

    NOTE: To improve security, change the scope of the role assignment to a resource group instead of a subscription.

AzCLI


2. Build the Ansible Container

Build the Ansible container image.

Change to the \ansible-container\$version directory, $version represents the version of Ansible you want to run.

docker build . -t ansible

3. Run the Ansible Container

Output the required Azure AD Service Principal information

@{
    subscriptionId = (Get-AzContext).Subscription.Id
    clientid = (Get-AzADServicePrincipal -DisplayName 'ansible').ApplicationId.Guid
    tenantid = (Get-AzContext).Tenant.Id
}

Run the Container

Windows

docker run -it --rm --volume ${PWD}:/ansible --workdir /ansible `
--env "AZURE_SUBSCRIPTION_ID=<Azure_Subscription_ID>" `
--env "AZURE_CLIENT_ID=<Service_Principal_Application_ID>" `
--env "AZURE_SECRET=<Service_Principal_Password>" `
--env "AZURE_TENANT=<Azure_Tenant>" `
ansible

Linux

docker run -it --rm --volume "$(pwd):/ansible" --workdir /ansible \
--env "AZURE_SUBSCRIPTION_ID=<Azure_Subscription_ID>" \
--env "AZURE_CLIENT_ID=<Service_Principal_Application_ID>" \
--env "AZURE_SECRET=<Service_Principal_Password>" \
--env "AZURE_TENANT=<Azure_Tenant>" \
ansible

Replace <Values> with the information output in step 3.

ansible-azure-samples's People

Contributors

duffney avatar

Watchers

 avatar  avatar

Forkers

mnawaz14

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.