https://github.com/bugbiteme/demo-tform-basic-ec2-with-ansible
Spin up and connect to an EC2 instance
https://github.com/bugbiteme/demo-tform-basic-ec2-with-ansible
Last synced: 9 months ago
JSON representation
Spin up and connect to an EC2 instance
- Host: GitHub
- URL: https://github.com/bugbiteme/demo-tform-basic-ec2-with-ansible
- Owner: bugbiteme
- Created: 2020-10-05T20:37:56.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-03-24T18:24:19.000Z (about 3 years ago)
- Last Synced: 2025-08-02T09:12:21.190Z (11 months ago)
- Language: HCL
- Size: 21.5 KB
- Stars: 3
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Instructions
You can use terraform on its own to spin up a number of Red Hat Enterprise Linux
EC2 instances in AWS (version 8.4)
Feel free to set the variables how you see fit
Terraform also produces a dynamic Ansible inventory file that can be used in
playbooks for configuring these sytems.
As an example, I have created a playbook that installs httpd on each new system, along
with a hello message in index.html, diplaying the OS version
## Prerequisits
Install the following on your local system:
- AWS cli
- terraform
- ansible (core)
## To run the terraform script on its own
`terraform init`
`terraform apply` (type "yes" when prompted)
output shows all the public IP addresses, as well as a cli string to ssh into one of
them.
delete everything by typing
`terraform destroy`
## To run the ansible playbook
Once your ec2 instances have been provisioned, run the command
`ansible-playbook -i inventory playbook.yml`
This will accomplish installing and testing httpd
## To run them on one swoop
I have created a helper sctipt called 'provision-and-config.sh' that does it all together
`sh ./provision-and-config.sh `
examples:
Just one ec2 instance (default)
`sh ./provision-and-config.sh`
ec2 instances == 3
`sh ./provision-and-config.sh 3`
run `terraform destroy` afterwards when you are done
# For RHEL Insight Setup, run these scripts instead
Additional playbooks have been added to register your EC2 instances with a RHEL subscription
and add them to Insights inventory:
- `rhel-reg-insights.yml`
Usage:
`ansible-playbook -i inventory rhel-reg-insights.yml --vault-id @prompt`
Note:
vault data set in `vars/reg-data.yml` and must be encrypted with `ansible-vault`
```
ansible-vault edit vars/reg-data.yml
.
.
username:
password:
```
Playbook to remove EC2 instances from the Insights inventory and unregister them:
- `rhel-unreg-insights.yml`
Scripts to provision/deprovision and register/unregister have been created as well:
- `rhel-provision-and-register.sh`
- `rhel-deprovision-and-unregister.sh`
# Additional Notes
## How to activate RHEL with your subscription via the command line
### Prerequisites
- Have a valid Red Hat Subscription
### Steps
- `sudo subscription-manager register --username --password --auto-attach`
## How to register your RHEL system with Red Hat Insights via the command line (RHEL 8.4)
### Prerequisites
- Activate your RHEL (see above)
- [Check Insights on how to add based on version of RHEL](https://console.redhat.com/insights/registration)
### Steps
- `sudo insights-client --register`
or
- `sudo rhc connect -u -p `
## To unregister RHEL system with Insights (decommisioning)
- `sudo insights-client --unregister`
## To ungregister RHEL system from subscription
- `sudo subscription-manager unregister`