Skip to content

Commit b71f828

Browse files
committed
added basic files. good simple working version for ec2 info and create instance.
1 parent 9816201 commit b71f828

9 files changed

+217
-1
lines changed

.gitignore

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2+
3+
4+
# THE ORDER OF THE FOLLOWING IS IMPORTANT! If we put secrets/* after, this does not work:
5+
secrets/*
6+
!secrets/.gitkeep
7+
8+
.idea
9+
110
# Byte-compiled / optimized / DLL files
211
__pycache__/
312
*.py[cod]
@@ -82,7 +91,7 @@ profile_default/
8291
ipython_config.py
8392

8493
# pyenv
85-
.python-version
94+
#.python-version
8695

8796
# pipenv
8897
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.

.python-version

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ve.ansimy
2+

ansible.cfg

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; ansible.cfg - project root
2+
3+
[defaults]
4+
inventory = inventory.yaml
5+
remote_user = ec2-user
6+
private_key_file = secrets/ssh_key_authorized_on_managed_nodes.pem
7+
playbook = play-info.yaml
8+
vpc_subnet_id = XXXXXXXX_YOUR_SUBNET_ID_XXXXXXXX
9+
stdout_callback = yaml
10+
11+
12+
; If you also authorized your default pub key on your managed hosts, then this might also work:
13+
;private_key_file = ~/.ssh/id_rsa.pub
14+
15+
; Human-readable output: stdout_callback = yaml
16+

inventory.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
3+
groupmain:
4+
vars:
5+
ansible_connection: ssh
6+
# ansible_user: ec2_user
7+
# ansible_ssh_public_key_file: ~/.ssh/id_rsa.pub
8+
hosts:
9+
XXfoobarXX:
10+
ansible_host: XXXX.XXXX.XXXX.XXXX
11+
XXwidgetXX:
12+
ansible_host: XXXX.XXXX.XXXX.XXXX
13+
XXgizmoXX:
14+
ansible_host: XXXX.XXXX.XXXX.XXXX
15+
XXgadgetXX:
16+
ansible_host: XXXX.XXXX.XXXX.XXXX
17+
localhost:
18+
ansible_host: 127.0.0.1
19+
ansible_connection: local
20+
21+
...
22+
23+
# ansible_connection: ssh
24+
# ansible_user: ec2_user
25+
# ansible_ssh_private_key_file: secrets/ssh_key_authorized_on_managed_nodes.pem
26+

play-info.yaml

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
# play-info.yml
3+
4+
-
5+
name: Play01 - EC2 fresh instance - Gather Information Before Setup
6+
hosts: groupmain
7+
tasks:
8+
####
9+
- name: Task0101 - Date, Time -- date
10+
command: date
11+
register: out_date
12+
- name: SHOW Task0101
13+
debug:
14+
var: out_date.stdout_lines
15+
####
16+
- name: Task0102 - Locate env (we need env for portable shebangs) -- which env
17+
command: which env
18+
register: out_which_env
19+
- name: SHOW Task0102
20+
debug:
21+
var: out_which_env.stdout_lines
22+
####
23+
- name: Task0103 - Locate bash (we use bash for everything) -- which bash
24+
command: which bash
25+
register: out_which_bash
26+
- name: SHOW Task0103
27+
debug:
28+
var: out_which_bash.stdout_lines
29+
####
30+
- name: Task0104 - System and Kernel Info -- uname -a
31+
command: uname -a
32+
register: out_uname
33+
- name: SHOW Task0104
34+
debug:
35+
var: out_uname.stdout_lines
36+
####
37+
- name: Task0105 - Proc Version -- cat /proc/version
38+
command: cat /proc/version
39+
register: out_version
40+
- name: SHOW Task0105
41+
debug:
42+
var: out_version.stdout_lines
43+
####
44+
- name: Task0106 - Process Table -- ps aux
45+
command: ps aux
46+
register: out_ps
47+
- name: SHOW Task0106
48+
debug:
49+
var: out_ps.stdout_lines
50+
####
51+
- name: Task0107 - Memory Stats -- vmstat
52+
command: vmstat
53+
register: out_vmstat
54+
- name: SHOW Task0107
55+
debug:
56+
var: out_vmstat.stdout_lines
57+
####
58+
- name: Task0108 - IO Stats -- iostat
59+
command: iostat
60+
register: out_iostat
61+
- name: SHOW Task0108
62+
debug:
63+
var: out_iostat.stdout_lines
64+
####
65+
- name: Task0109 - PATH -- echo "$PATH"
66+
command: echo "$PATH"
67+
register: out_path
68+
- name: SHOW Task0109
69+
debug:
70+
var: out_path.stdout_lines
71+
####
72+
- name: Task0110 - List Block Devices -- lsblk
73+
command: lsblk
74+
register: out_lsblk
75+
- name: SHOW Task0110
76+
debug:
77+
var: out_slblk.stdout_lines
78+
####
79+
- name: Task0111 - Disk Freespace -- df -h
80+
command: df -h
81+
register: out_df
82+
- name: SHOW Task0111
83+
debug:
84+
var: out_df.stdout_lines
85+
####
86+
- name: Task0112 - List Filesystem Mount Points -- mount
87+
command: mount
88+
register: out_mount
89+
- name: SHOW Task0112
90+
debug:
91+
var: out_mount.stdout_lines
92+
####
93+
- name: Task0113 - List All System Limits - (file descriptors, stack size, etc.) (VIA ansible.builtin.shell) -- ulimit -a
94+
ansible.builtin.shell:
95+
cmd: ulimit -a
96+
register: out_ulimit
97+
- name: SHOW Task0113
98+
debug:
99+
var: out_ulimit.stdout_lines
100+
####
101+
- name: Task0114 - Environment Variables -- env
102+
command: env
103+
register: out_env
104+
- name: SHOW Task0114
105+
debug:
106+
var: out_env.stdout_lines
107+
####
108+
109+
...

play-new-ec2-micro.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
# play-new-ec2-micro.yml
3+
4+
-
5+
name: Play02 - AWS CLI - Create new EC2 t2.micro instance
6+
hosts: localhost
7+
tasks:
8+
########
9+
- name: Block01 - AWS Info
10+
block:
11+
- name: Task-B01-T01 - Get info on all running instances
12+
community.aws.ec2_instance_info:
13+
register: out_ec2_instance_list
14+
- name: Task-B01-T02 show Task-B01-T01
15+
debug:
16+
var: out_ec2_instance_list
17+
########
18+
- name: Block02 - Create New EC2 Instance - t2.micro
19+
block:
20+
- name: Task-B02-T01 - Create the new EC2 instance -------- NEW t2.micro
21+
amazon.aws.ec2_instance:
22+
name: "ansiblemyec2"
23+
vpc_subnet_id: XXXXXXXX_YOUR_SUBNET_ID_XXXXXXXX
24+
instance_type: t2.micro
25+
image_id: ami-0b029b1931b347543
26+
metadata_options:
27+
http_endpoint: enabled
28+
####
29+
30+
...
31+
32+
33+
# https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_instance_module.html
34+
35+
# Current, basic Amazon Linux OS Image (Red Hat derivative): image_id: ami-0b029b1931b347543
36+

requirements.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# requirements.txt
2+
3+
ansible
4+
botbo3
5+

secrets/.gitkeep

Whitespace-only changes.

setup.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /usr/bin/env bash
2+
3+
# TODO: Improve this setup script a lot. See the project README.md for better info.
4+
5+
# Prior to this:
6+
# Install the latest Python into your Pyenv: pyenv install 3.11.2
7+
# pyenv virtualenv 3.11.2 ve.ansible
8+
# Also, create .python-version in project root, containing: ve.ansible
9+
10+
pip install --upgrade pip
11+
pip install --upgrade setuptools
12+
pip install --upgrade wheel
13+

0 commit comments

Comments
 (0)