
Automate AWS CLI Deployment Using Ansible – Step by Step
Leverage the power of Ansible to quickly prepare and install the AWS CLI in your environment, enabling you to get started with AWS faster than ever.
$ aws <command> <subcommand> [options and parameters]
- The basic call to the aws program.
- The top-level command that typically corresponds to an AWS service supported by the AWS CLI.
- The subcommand that specifies the operation to be performed.
- The general CLI options, or parameters required for the operation. You can specify these in any order, as long as you follow the first three parts. If a unique parameter is specified multiple times, only the last value applies.
--output json
--output table
--output text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
root@amaury:~# aws ec2 start-instances --instance-ids i-082f3d641e2c07a80 i-0e17198ccef021229 i-0e709937096f6f554
{
"StartingInstances": [
{
"InstanceId": "i-0e709937096f6f554",
"CurrentState": {
"Code": 0,
"Name": "pending"
},
"PreviousState": {
"Code": 80,
"Name": "stopped"
}
},
{
"InstanceId": "i-0e17198ccef021229",
"CurrentState": {
"Code": 0,
"Name": "pending"
},
"PreviousState": {
"Code": 80,
"Name": "stopped"
}
},
{
"InstanceId": "i-082f3d641e2c07a80",
"CurrentState": {
"Code": 0,
"Name": "pending"
},
"PreviousState": {
"Code": 80,
"Name": "stopped"
}
}
]
}
- Provisioning;
- Configuration management;
- Continuous delivery;
- Security;
- Orchestration;
- Application deployment.
- Updates the APT package index.
- Installs
curl
andunzip
. - Downloads the AWS CLI installer.
- Unzips the installer.
- Installs the AWS CLI.
- Verifies the installation and displays the version.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
- name: Install AWS CLI on Ubuntu
hosts: local
become: true
tasks:
- name: Update apt package index
apt:
update_cache: yes
- name: Install required packages for AWS CLI
apt:
name:
- curl
- unzip
state: present
- name: Download AWS CLI installer
get_url:
url: "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"
dest: "/tmp/awscliv2.zip"
- name: Unzip AWS CLI installer
unarchive:
src: "/tmp/awscliv2.zip"
dest: "/tmp"
remote_src: yes
- name: Run AWS CLI installer
command: "/tmp/aws/install"
- name: Verify AWS CLI installation
command: "aws --version"
register: aws_cli_version
- name: Display AWS CLI version
debug:
msg: "{{ aws_cli_version.stdout }}"
1
2
3
4
5
$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLG
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEW
Default region name [None]: us-west-2
Default output format [None]: json
1
2
3
4
5
6
7
8
9
10
11
12
13
$ aws ec2 describe-instances --query "Reservations[*].Instances[*].InstanceId"
[
[
"i-02f5aa06af8838f8a",
"i-01cb845d279218c20",
"i-00835abcb71700b5e"
],
[
"i-082f3d641e2c07a50",
"i-0e709937096f6f525",
"i-0e17198ccef02124f"
]
]
1
2
3
4
5
6
7
8
9
10
11
12
13
$ aws ec2 describe-instances --query "Reservations[*].Instances[*].VpcId"
[
[
"vpc-2f0bb010",
"vpc-2f0bb010",
"vpc-2f0bb010"
],
[
"vpc-2f0bb010",
"vpc-2f0bb010",
"vpc-2f0bb010"
]
]