Skip to content

Instantly share code, notes, and snippets.

nivleshc

Block or report user

Report or block nivleshc

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nivleshc
nivleshc / ansible-aws-inventory-main-03.yml
Created Apr 16, 2019
Part 3 of ansible-aws-inventory-main.yml file
View ansible-aws-inventory-main-03.yml
#define output file names. These will be prepended with run date/time in iso6801 format
- output_root_folder: /Users/nivleshc/Documents/OneDrive/Personal/Studies/AWS/output/raw/
- outputfile_variablename_suffix: "_outputfile"
- outputfileheader_variablename_suffix: "_outputfile_header"
- vpc_outputfile: "{{ output_root_folder }}{{ ansible_date_time.iso8601 }}_vpc.csv"
- subnet_outputfile: "{{ output_root_folder }}{{ ansible_date_time.iso8601 }}_subnet.csv"
- igw_outputfile: "{{ output_root_folder }}{{ ansible_date_time.iso8601 }}_igw.csv"
- cgw_outputfile: "{{ output_root_folder }}{{ ansible_date_time.iso8601 }}_cgw.csv"
- vgw_outputfile: "{{ output_root_folder }}{{ ansible_date_time.iso8601 }}_vgw.csv"
- ami_outputfile: "{{ output_root_folder }}{{ ansible_date_time.iso8601 }}_ami.csv"
@nivleshc
nivleshc / ansible-aws-inventory-main-04.yml
Created Apr 16, 2019
Part 4 of ansible-aws-inventory-main.yml file
View ansible-aws-inventory-main-04.yml
#the following variables are used to enable or disable inventory for a particular resource. Use true to enable and false to disable
- inventory_vpc: true
- inventory_subnet: true
- inventory_igw: true
- inventory_cgw: true
- inventory_vgw: true
- inventory_ami: true
- inventory_eip: true
- inventory_snapshot: true
- inventory_volume: true
@nivleshc
nivleshc / ansible-aws-inventory-main-05.yml
Created Apr 16, 2019
Part 5 of ansible-aws-inventory-main.yml file
View ansible-aws-inventory-main-05.yml
tasks:
- name: initialise output files with headers
lineinfile:
state: present
create: yes
path: "{{ lookup('vars', item + outputfile_variablename_suffix) }}"
line: "{{ lookup('vars', item + outputfileheader_variablename_suffix) }}"
insertbefore: BOF
with_items:
- vpc
@nivleshc
nivleshc / ansible-aws-inventory-main-06.yml
Created Apr 16, 2019
Part 6 of ansible-aws-inventory-main.yml file
View ansible-aws-inventory-main-06.yml
- name: find all applicable resources within region
include_tasks: ansible-aws-inventory-worker.yml
loop: "{{ aws_regions }}"
loop_control:
loop_var: aws_region
label: "{{ aws_region }}"
@nivleshc
nivleshc / ansible-aws-inventory-main-07.yml
Created Apr 16, 2019
Part 7 of ansible-aws-inventory-main.yml file
View ansible-aws-inventory-main-07.yml
- name: print out the output filenames for each of the resoureces inventoried
debug:
msg:
- "{{ item }} output filename: {{ lookup('vars', item + outputfile_variablename_suffix) }}"
with_items:
- vpc
- subnet
- igw
- cgw
- vgw
@nivleshc
nivleshc / ansible-aws-inventory-hosts
Created Apr 12, 2019
This is the ansible inventory file that will be used by ansible-aws-inventory-main.yml
@nivleshc
nivleshc / ansible-aws-inventory-worker.yml
Created Apr 12, 2019
Ansible Inventory Worker file. This is the file which actually carries out all the inventory tasks. It is called by the main file
View ansible-aws-inventory-worker.yml
# Name: ansible-aws-inventory-worker.yml
# Description: this is the worker file that called the main file (ansible-aws-inventory-main.yml) to to create an inventory of all the
# specific aws resources. This file, the worker file and the ansible inventory file must be placed in the same folder
# Prerequisites:
# - the worker file (ansible-aws-inventory-worker.yml) and the ansible hosts file must be present in the same folder as this file (ansible-aws-inventory-main.yml)
# - this script requires read access to all resources it will be querying. An AWS IAM user account must be created with the necessary permissions and with access keys enabled.
# At a minimum, to query all the resources mentioned above, the following permissions are required
# - AmazonVPCReadOnlyAccess
# - AmazonEC2ReadOnlyAccess
# - ElasticLoadBalancingReadOnly
@nivleshc
nivleshc / ansible-aws-inventory-main.yml
Created Apr 12, 2019
The main inventory file - declare variables here. This calls the worker file (which must be prese
View ansible-aws-inventory-main.yml
---
# Name: ansible-aws-inventory-main.yml
# Description: this is the main file that calls the worker file (ansible-aws-inventory-worker.yml) to create an inventory of all the
# specific aws resources.
# Below are the resources that will be inventoried
# - vpc
# - subnet
# - igw
# - cgw
# - vgw
@nivleshc
nivleshc / ansible-aws-inventory-main-02.yml
Created Apr 11, 2019
Part 2 of the ansible-aws-inventory-main.yml file
View ansible-aws-inventory-main-02.yml
#define all output file headers
- vpc_outputfile_header: "Region;VPC ID;Is_Default;State;CIDR Block;Enable DNS Hostnames;Enable DNS Support;DHCP Options ID;Instance Tenancy"
- subnet_outputfile_header: "Region;Subnet ID;VPC ID;avaialability zone;cidr_block;available_ip_address_count;default_for_az;map_public_ip_on_launch;state"
- igw_outputfile_header: "Region;IGW ID;VPC ID;State;Tags"
- cgw_outputfile_header: "Region;CGW ID;BGP ASN;ip address;state;type;tags"
- vgw_outputfile_header: "Region;VGW ID;State;type;attachments;Tags"
- ami_outputfile_header: "Region;image_id;name;creation_date;state;is_public;description"
- eip_outputfile_header: "Region;allocation_id;association_id;domain;attached to(instance_id);network_interface_id;private_ip_address;public_ip;public_ipv4_pool"
- snapshot_outputfile_header: "Region;snapshot_id;owner_id;start_time;progress;state;encrypted;volume_id;volume_size;description"
- volume_outputfile_header: "Region;volume_id;volume_type;size;iops;encrypted;status;regio
@nivleshc
nivleshc / ansible-aws-inventory-main-01.yml
Last active Apr 11, 2019
Part 1 of ansible-aws-inventory-main.yml file
View ansible-aws-inventory-main-01.yml
- hosts: localhost
connection: local
gather_facts: yes
vars:
- aws_regions:
- us-east-1 #North Virginia
- us-east-2 #Ohio
- us-west-1 #North California
- us-west-2 #Oregon
- ap-south-1 #Mumbai
You can’t perform that action at this time.