Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the dynamic list of Ansible AWS

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to set the dynamic list of Ansible AWS". In the daily operation, I believe that many people have doubts about how to set the dynamic list of Ansible AWS. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to set the dynamic list of Ansible AWS". Next, please follow the editor to study!

Set up Ansible AWS dynamic manifest

1. Install the Boto library using pip. If you have not installed pip, follow this document to install-> install python pip

Pip install boto

two。 Download the manifest script to the / etc / ansible directory.

3. Make the file executable.

Chmod + x ec2.py

4. Download the ec2.ini file to the / etc / ansible directory.

5. The ec2.ini file has a default AWS configuration and can be read through the ec2.py file. Therefore, please comment out and configure the necessary parameters so that the query time is not too long. Such an example is the "regions" parameter. By default, this value is all. This allows you to make API calls to all areas. Therefore, it is best to mention only the specific aws area you are using.

Under the [credentials] section, you need to mention the abos access key and private key for the boto library to make API calls.

Alternatively, you can create a credential file at home, as shown below.

Touch / .aws/credentials

Open the credential file and enter it as shown below.

[default]

Aws_access_key_id = YOUR_ACCESS_KEY

Aws_secret_access_key = YOUR_SECRET_KEY

Note: if you are using an AWS instance for this setting and have an IAM role with access to the AWS service, you do not need to add the access key and secret key to the credential file

6 now, use the following command to test the list configuration.

. / ec2.py-- list

You should get the output shown below.

{

"_ meta": {

"hostvars": {}

}

}

If you have some instances running, you will get output containing all the instance details.

7. If you want to use the dynamic manifest as the default ansible manifest, you need to edit the ansible.cfg file that exists in the / etc / ansible directory and search for manifest parameters in ansible.cfg. Change the inventory parameter values as shown below.

Inventory = / etc/ansible/ec2.py

You can now run the normal ansible command on the dynamic manifest resource. For example, the following command runs the ping command on all running ec2 instances that are obtained using a dynamic manifest.

Ansible all-m ping

At this point, the study on "how to set the dynamic list of Ansible AWS" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report