February 2018
Intermediate to advanced
200 pages
5h 51m
English
To present a realistic example, we have created a simple inventory script for Amazon Web Service in Python. The code is available on GitHub (https://github.com/ansible-cookbook/ec2_tags_inventory):
#!/usr/bin/env pythonimport boto3import jsonimport ConfigParserimport osdef get_address(instance): if "PublicIpAddress" in instance: address = instance["PublicIpAddress"] else: address = instance["PrivateIpAddress"] return addressif os.path.isfile('ec2.ini'): config_path = 'ec2.ini'elif os.path.isfile(os.path.expanduser('~/ec2.ini')): config_path = os.path.expanduser('~/ec2.ini')config = ConfigParser.ConfigParser()config.read(config_path)id = config.get("credentials", "aws_access_key_id", raw=True)key = config.get("credentials", ...Read now
Unlock full access