How to setup Ansible on Red Hat Linux VM and Integrate with Azure Cloud?
Ansible is #1 configuration management tool. It can also be used for infrastructure provisioning as well. or You can use Ansible in combination of Terraform which can take care of infra automation and Ansible can do configuration management. We will be setting up Ansible on Red Hat VM in Azure cloud And create some resources in Azure Cloud by using Ansible playbooks.
- Create new Red Hat VM in Azure Cloud for setting up Ansible, just open port 22 in firewall rule.
- Install Azure CLI on Red Hat Linus VM
- Service principal to create any resources in Azure cloud using Azure CLI
sudo hostnamectl set-hostname AnsibleMgmtNode
sudo yum update -y
To configure Azure credentials, you need the following information:
- Your Azure subscription ID and tenant ID
- The service principal application ID and secret
Create an Azure Service Principal
Configure the Ansible credentials using one of the following techniques:
Option 1: Create Ansible credentials file
In this section, you create a local credentials file to provide credentials to Ansible. For security reasons, credential files should only be used in development environments.
mkdir ~/.azure
vi ~/.azure/credentials
Option 2: Define Ansible environment variables
On the host virtual machine, export the service principal values to configure your Ansible credentials.
export AZURE_SUBSCRIPTION_ID=<subscription_id> export AZURE_CLIENT_ID=<service_principal_app_id> export AZURE_SECRET=<service_principal_password> export AZURE_TENANT=<service_principal_tenant_id>
Test Ansible installation
You now have a virtual machine with Ansible installed and configured!
This section shows how to create a test resource group within your new Ansible configuration. If you don't need to do that, you can skip this section.
Option 1: Use an ad-hoc ansible command
Run the following ad-hoc Ansible command to create a resource group:
ansible localhost -m azure_rm_resourcegroup -a "name=my-rg123 location=eastus"
Option 2: Write and run an Ansible playbook
Create a simple playbook to create resource group in Azure.
sudo vi create-rg.yml
---
- hosts: localhost
connection: local
tasks:
- name: Creating resource group
azure_rm_resourcegroup:
name: "myResourceGroup"
location: "eastus"
Execute the playbook using ansible-playbook command.
ansible-playbook create-rg.yml
sudo vi delete-rg.yml
- hosts: localhost tasks: - name: Deleting resource group - "{{ name }}" azure_rm_resourcegroup: name: "{{ name }}" state: absent register: rg - debug: var: rg
ansible-playbook delete-rg.yml --extra-vars "name=myResourceGroup"
No comments:
Post a Comment