Install Ansible on a provisioned machine using Terraform [closed] - amazon-ec2

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I just provisioned an EC2 instance using terraform.
Now I'd like to install ansible on said machine in an automated way using terraform.
Is there a way to do so?

Just want to clarify:
Usually there is no need to install ansible on a machine after provisioning it since there isn't a daemon or agent required to be able to execute ansible tasks on a remote machine.
The usual workflow would be to provision machines with terraform and then configure them via ansible from a remote machine that can reach the newly created ones. So it only ever needs one machine that has ansible installed (which could as well be your local machine in case you can directly connect to the provisioned instances).
However, to answer your question on how you can install ansible (or anything else) on a machine that you just provisioned with terraform:
There is a provisioner called remote-exec: https://www.terraform.io/docs/language/resources/provisioners/remote-exec.html
Just use it within your instance declaration.
It comes with an argument called inline which you can use to write down your installation commands. There are many different ways of installing ansible, depending on your setup some of those may not even work, therefore I cannot tell you which one is the best for you.
However, to give you an example of how to use the provisioner:
resource "aws_instance" "my-instance" {
instance_type = "t3.micro"
# ...
provisioner "remote-exec" {
inline = [
"apt update",
"apt install <package>",
]
}
}

Related

Bash scripting to copy [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed last year.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
Improve this question
Please share any bash script to run s3 copy commands. I have already tried separate Script to call the rclone command for each agency to backup EC2 instance windows server data to S3.
The command below syncs the current directory to an S3 bucket using a named profile.
aws s3 sync . $S3_BUCKET_URL --profile $YOUR_PROFILE_BRO
The next command syncs the S3 bucket to the current directory using a named profile.
aws s3 sync $S3_BUCKET_URL . --profile $YOUR_PROFILE_BRO
The next command copies a file (file.txt) from your machine to S3 using the default profile of your machine.
aws s3 cp file.txt s3://my-bucket/
Of course, you need an aws-cli and AWS credential pair (secret key & secret key id) to make this work from your machine or on-premise networks. If you want to copy from EC2 to S3, you can assign IAM roles that posses permissions to write/read objects to that EC2 and you should be good to go.

Can I look at files my code makes on heroku? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a discord bot that saves JSON files on the dir he is in so it could work on more than one server without colliding.
I finished my code and I uploaded it to heroku for hosting. The thing is , when I ran the code locally I could see the files that were being created for each server for testing but now I don't know how to reach them.
Is there a way to check all the files I have in heroku without downloading everything down?
You can install Heroku CLI and then access your files using:
heroku login
heroku run bash -a APPNAME
But be aware that Heroku uses an ephemeral filesystem. This means that your local filesystem is only accessible to a single dyno, and once the dyno is stopped, restarted, or moved, all files on the local filesystem are destroyed.
You could use a service like Amazon S3 to store your files in a more permanent way.

How to repeatedly/automatically setup ansible server itself

I'm setting up a ansible server and I have a basic question.
What is the best practice regarding setting up the first ansible server itself ? (Installing specific version's python, ansible, etc.)
Ansible server is used to setup other non-ansible (and ansible servers),
but the first/root ansible server can't be helped by any ansible servers.
I'm writing a shell script just for the first one but I'm feeling I'm in early 2000.
You can get all the information you require to setup ansible at the below given links,
WATCH ANSIBLE QUICK START VIDEO
HOW ANSIBLE WORKS
DOWNLOAD ANSIBLE
I struggled with the same issue. I solved it in the following way:
Set up the first server manually (bear with me!) to a bare Ansible control server.
Create a second server with only the OS, no Ansible yet.
Write scripts on the first server to build up the second server to a fully specced Ansible control server. I did need to have an extra (shell)-script that installs the required galaxy roles. You can use Ansible to have those roles automatically installed on the second server.
On the second server, pull (you're Ansible scripts are in version control right?) the scripts and use them to keep the first server uptodate.
Switch regularly between using the first and second server as Ansible control server.
Yes, this does indeed add overhead (extra server, extra switching). But this way you make sure that when both servers die, you only need to have a first simple server with a bare Ansible and either build up itself or a second server.

Forgot Amazon EC2 instance [windows 2008 server] password. [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I cannot retrieve the password for my EC2 instance running Windows 2008 server. I want this particular instance and my get password does not work.
Any work around how I can retrieve the password.
Your server is launched from an AMI most probably that is the reason you cannot retrieve your password. It has happened to me in past. In short what you have to do is create an image of the existing instance and then launch a new instance using that image.
create a snapshot with ec2-create-snapshot
attach the snapshot to a new instance.

Best tool to work with Amazon RDS? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I just found the wonderful ElasticFox, a Firefox plugin that makes working with Amazon EC2 much more enjoyable. Is there a similar tool for Amazon RDS?
Or, rather, what is the best/easiest tool to work with RDS?
I have been using MySQL Workbench http://www.mysql.com/products/workbench/ with RDS and it works great. Very easy to create and save a new database service instance. Click "New Server Instance" under "Server Administration" and follow the prompts. You will need to enter the information provided in the AWS RDS webpage for that instance (for example, it's endpoint).
NOTE: In order for you to actually connect, you MUST add your IP address in the "DB Security Groups." The link is in the left-hand column, which is titled "Navigation." I use the "CIDR/IP" option (the other is EC2 Security Group). Make sure to include a /## after the IP, such as the /32 they use in the example. In a few seconds, the IP address should be authorized.
After the new security group has been authorized, the "DB Security Groups" of the DB Instance running MySql needs to be updated to include this newly created security group. After this updation, the "DB Security Groups" should show atleast two 'active' security groups, one which was already present previously and other which was newly created in the previous step.
After that, go back to MySQL Workbench and complete the New Server Instance creation process.
I'd say the AWS Console and RDS CLI along with MySQL client itself are totally sufficient.
Anything particular you are looking for?
AWS console is well enough to monitor and configure the RDS. However we cant change some parameters with AWS Console (like mysql.ini parameters). In that case you have to use RDS Command Line tools.
Still if you dont want to mess with Command line APIs, you can use cloud management systems and use it (free edition) as GUI tool such as RightScale
Here is post you can see how third party GUI tools can be used to work with Amazon RDS
Try DBHawk from Datasparc. It can connect to cloud databases such as Amazon RDS and MS Azure.

Resources