Skip to content

Commit 52607e8

Browse files
committed
Replaced hard-coded values with placeholders, and other fixes
1 parent 8290e68 commit 52607e8

File tree

2 files changed

+34
-58
lines changed

2 files changed

+34
-58
lines changed

articles/ansible/ansible-run-playbook-in-cloudshell.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ In this tutorial, you learn how to use Bash within Cloud Shell to configure an A
1616

1717
## Prerequisites
1818

19-
- **Azure subscription** - If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio) before you begin.
19+
- **Azure subscription** - If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio).
2020

2121
- **Configure Azure Cloud Shell** - If you are new to Azure Cloud Shell, the article, [Quickstart for Bash in Azure Cloud Shell](https://docs.microsoft.com/azure/cloud-shell/quickstart), illustrates how to start and configure Cloud Shell.
2222

articles/virtual-machines/linux/ansible-install-configure.md

+33-57
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ Ansible allows you to automate the deployment and configuration of resources in
1616

1717
For more installation options and steps for additional platforms, see the [Ansible install guide](https://docs.ansible.com/ansible/intro_installation.html).
1818

19-
One of the easiest ways to use Ansible with Azure is with the Azure Cloud Shell, a browser-based shell experience to manage and develop Azure resources. Ansible is pre-installed in the Cloud Shell, you can follow []() to configure your Cloud Shell and try it. For a list of additional tools also available in the Cloud Shell, see [Features and tools for Bash in the Azure Cloud Shell](../../cloud-shell/features.md#tools).
19+
One of the easiest ways to use Ansible with Azure is with the [Azure Cloud Shell](https://docs.microsoft.com/en-us/azure/cloud-shell/overview), a browser-based shell experience to manage and develop Azure resources. Ansible is pre-installed in the Cloud Shell. For a list of additional tools available in the Cloud Shell, see [Features and tools for Bash in the Azure Cloud Shell](../../cloud-shell/features.md#tools).
2020

21-
The following instructions show you how to create a Linux VM for various distros and then install Ansible.
21+
The following instructions show you how to create a Linux virtual machine for various distros and then install Ansible.
2222

2323
## Prerequisites
24-
To manage Azure resources with Ansible, you need the following prerequisites:
2524

26-
- **Azure subscription** - If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio) before you begin.
25+
- **Azure subscription** - If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio).
2726

28-
- **Linux machine** - If you don't have a Linux machine, create a [Linux virtual machine](/virtual-machines/linux/quick-create-cli.md) before you begin.
27+
- **Access to Linux or a Linux virtual machine** - If you don't have a Linux machine, create a [Linux virtual machine](/virtual-machines/linux/quick-create-cli.md).
28+
29+
- **Azure service principal**: Follow the directions in the section of the **Create the service principal** section in the article, [Create an Azure service principal with Azure CLI 2.0](/cli/azure/create-an-azure-service-principal-azure-cli?view=azure-cli-latest#create-the-service-principal). Take note of the values for the **appId**, **displayName**, **password**, and **tenant**.
2930

3031
## Install Ansible
3132

@@ -37,7 +38,7 @@ Sign in to your Linux machine and select one of the following distros for steps
3738

3839
### CentOS 7.4
3940

40-
Install the required packages for the Azure Python SDK modules and Ansible as follows:
41+
Install the required packages for the Azure Python SDK modules and Ansible by entering the following commands in a terminal or Bash window:
4142

4243
```bash
4344
## Install pre-requisite packages
@@ -48,11 +49,12 @@ sudo yum install -y python-pip python-wheel
4849
sudo pip install ansible[azure]
4950
```
5051

51-
Now move on to [Create Azure credentials](#create-azure-credentials).
52+
Follow the instructions outlined in the section, [Create Azure credentials](#create-azure-credentials).
5253

5354
### Ubuntu 16.04 LTS
5455

55-
Install the required packages for the Azure Python SDK modules and Ansible as follows:
56+
Install the required packages for the Azure Python SDK modules and Ansible by entering the following commands in a terminal or Bash window:
57+
5658

5759
```bash
5860
## Install pre-requisite packages
@@ -62,10 +64,11 @@ sudo apt-get update && sudo apt-get install -y libssl-dev libffi-dev python-dev
6264
sudo pip install ansible[azure]
6365
```
6466

65-
Now move on to [Create Azure credentials](#create-azure-credentials).
67+
Follow the instructions outlined in the section, [Create Azure credentials](#create-azure-credentials).
6668

6769
### SLES 12 SP2
68-
Install the required packages for the Azure Python SDK modules and Ansible as follows:
70+
71+
Install the required packages for the Azure Python SDK modules and Ansible by entering the following commands in a terminal or Bash window:
6972

7073
```bash
7174
## Install pre-requisite packages
@@ -79,81 +82,54 @@ sudo pip install ansible[azure]
7982
sudo pip uninstall -y cryptography
8083
```
8184

82-
Now move on to [Create Azure credentials](#create-azure-credentials).
85+
Follow the instructions outlined in the section, [Create Azure credentials](#create-azure-credentials).
8386

8487
## Create Azure credentials
8588

86-
Ansible communicates with Azure using a username and password or a service principal. An Azure service principal is a security identity that you can use with apps, services, and automation tools like Ansible. You control and define the permissions as to what operations the service principal can perform in Azure. To improve security over just providing a username and password, this example creates a basic service principal.
87-
88-
In the Azure Cloud Shell or on your host machine if you installed [AZ CLI](), create a service principal.
89-
90-
To authenticate to Azure, you need to obtain your Azure subscription ID using [az account show](/cli/azure/account#az-account-show):
89+
The combination of the subscription ID and the information returned from creating the service principal is used to configure the Ansible credentials in one of two ways:
9190

92-
```azurecli-interactive
93-
az account show --query "{ subscription_id: id }"
94-
```
95-
96-
If you want to change you workspace to another subscription, using [az account set]():
97-
98-
```azurecli-interactive
99-
az account set -s <subscription-id>
100-
```
91+
- [Create an Ansible credentials file](#file-credentials)
92+
- [Use Ansible environment variables](#env-credentials)
10193

102-
Note the subscription ID.
103-
104-
Create a service principal using [az ad sp create-for-rbac](/cli/azure/ad/sp#az-ad-sp-create-for-rbac). The credentials that Ansible needs are output to the screen:
105-
106-
```azurecli-interactive
107-
az ad sp create-for-rbac --query '{"client_id": appId, "secret": password, "tenant": tenant}'
108-
```
109-
110-
An example of the output from the preceding commands is as follows:
111-
112-
```json
113-
{
114-
"client_id": "eec5624a-90f8-4386-8a87-02730b5410d5",
115-
"secret": "531dcffa-3aff-4488-99bb-4816c395ea3f",
116-
"tenant": "72f988bf-86f1-41af-91ab-2d7cd011db47"
117-
}
118-
```
119-
120-
You use the output of this command together with subscription ID to configure Ansible credentials in either [file](#file-credentials) or [environment variable](#env-credentials) ways.
94+
If you are going to use tools such as Ansible Tower or Jenkins, you will need to use the option of declaring the service principal values as environment variables.
12195

12296
### <span id="file-credentials"/> Create Ansible credentials file
12397

124-
To provide credentials to Ansible, you define environment variables or create a local credentials file. For more information about how to define Ansible credentials, see [Providing Credentials to Azure Modules](https://docs.ansible.com/ansible/guide_azure.html#providing-credentials-to-azure-modules).
98+
This section explains how to create a local credentials file to provide credentials to Ansible. For more information about how to define Ansible credentials, see [Providing Credentials to Azure Modules](https://docs.ansible.com/ansible/guide_azure.html#providing-credentials-to-azure-modules).
12599

126-
For a development environment, create a *credentials* file for Ansible on your host VM. Create a credentials file on the VM where you installed Ansible in a previous step:
100+
For a development environment, create a *credentials* file for Ansible on your host virtual machine as follows:
127101

128102
```bash
129103
mkdir ~/.azure
130104
vi ~/.azure/credentials
131105
```
132106

133-
The *credentials* file itself combines the subscription ID with the output of creating a service principal. Output from the previous [az ad sp create-for-rbac](/cli/azure/ad/sp#create-for-rbac) command is the same as needed for *client_id*, *secret*, and *tenant*. The following example *credentials* file shows these values matching the previous output. Enter your own values as follows:
107+
Insert the following lines into the *credentials* file - replacing the placeholders with the information from the service principal creation.
134108

135109
```bash
136110
[default]
137-
subscription_id=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
138-
client_id=eec5624a-90f8-4386-8a87-02730b5410d5
139-
secret=531dcffa-3aff-4488-99bb-4816c395ea3f
140-
tenant=72f988bf-86f1-41af-91ab-2d7cd011db47
111+
subscription_id=<your-subscription_id>
112+
client_id=<security-principal-appid>
113+
secret=<security-principal-password>
114+
tenant=<security-principal-tenant>
141115
```
142116

143117
Save and close the file.
144118

145119
### <span id="env-credentials"/>Use Ansible environment variables
146120

147-
You can configure you Ansible credentials by exporting it as environment variable. If you are going to use tools such as Ansible Tower or Jenkins, you need to define environment variables:
121+
This section explains how to configure your Ansible credentials by exporting them as environment variables.
122+
123+
In a terminal or Bash window, enter the following commands:
148124

149125
```bash
150-
export AZURE_SUBSCRIPTION_ID=xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
151-
export AZURE_CLIENT_ID=eec5624a-90f8-4386-8a87-02730b5410d5
152-
export AZURE_SECRET=531dcffa-3aff-4488-99bb-4816c395ea3f
153-
export AZURE_TENANT=72f988bf-86f1-41af-91ab-2d7cd011db47
126+
export AZURE_SUBSCRIPTION_ID=<your-subscription_id>
127+
export AZURE_CLIENT_ID=<security-principal-appid>
128+
export AZURE_SECRET=<security-principal-password>
129+
export AZURE_TENANT=<security-principal-tenant>
154130
```
155131

156-
## Verify
132+
## Verify the configuration
157133
To verify the successful configuration, you can now use Ansible to create a resource group.
158134

159135
[!INCLUDE [create-resource-group-with-ansible.md](../../../includes/ansible-create-resource-group.md)]

0 commit comments

Comments
 (0)