diff options
8 files changed, 189 insertions, 0 deletions
diff --git a/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/ansible.cfg b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/ansible.cfg new file mode 100644 index 0000000..3ea4292 --- /dev/null +++ b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/ansible.cfg @@ -0,0 +1,14 @@ +[defaults] +inventory = /root/aws/ip.txt +host_key_checking= False +private_key_file = /root/aws/mykey.pem +remote_user=vyos +[privilege_escalation] +[inventory] +[paramiko_connection] +[ssh_connection] +[persistent_connection] +[accelerate] +[selinux] +[colors] +[diff] diff --git a/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/group_vars/all b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/group_vars/all new file mode 100644 index 0000000..49ff69f --- /dev/null +++ b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/group_vars/all @@ -0,0 +1,3 @@ +ansible_connection: ansible.netcommon.network_cli +ansible_network_os: vyos.vyos.vyos +ansible_user: vyos diff --git a/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/instance.yml b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/instance.yml new file mode 100644 index 0000000..b8faa08 --- /dev/null +++ b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/instance.yml @@ -0,0 +1,16 @@ +- name: integration of terraform and ansible + hosts: all + gather_facts: 'no' + + tasks: + - name: "Wait 300 seconds, but only start checking after 60 seconds" + wait_for_connection: + delay: 60 + timeout: 300 + + - name: Configure general settings for the vyos hosts group + vyos_config: + lines: + - set system name-server 8.8.8.8 + save: + true diff --git a/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/mykey.pem b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/mykey.pem new file mode 100644 index 0000000..2fd39a4 --- /dev/null +++ b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Ansible/mykey.pem @@ -0,0 +1,5 @@ +-----BEGIN OPENSSH PRIVATE KEY----- + +Copy your key.pem from AWS + +-----END OPENSSH PRIVATE KEY----- diff --git a/Terraform/AWS_terraform_ansible_single_vyos_instance-main/README.md b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/README.md new file mode 100644 index 0000000..0577dfa --- /dev/null +++ b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/README.md @@ -0,0 +1,46 @@ +# AWS_terraform_ansible_single_vyos_instance +How to create a single instance and install your configuration using Terraform+Ansible+AWS +Step by step: +# AWS +1.1 Create an account with AWS and get your "access_key", "secret key" + +1.2 Create a key pair and download your .pem key + +1.3 Create a security group for the new VyOS instance +# Terraform +2.1 Create a UNIX or Windows instance + +2.2 Download and install Terraform + +2.3 Create the folder for example ../awsvyos/ + +2.4 Copy all files from my folder /Terraform into your Terraform project (vyos.tf, var.tf) +2.4.1 Please type the information into the strings 22, 35, 36 of file "vyos.tf" + +2.5 Type the commands : + + #cd /your folder + + #terraform init +# Ansible +3.1 Create a UNIX instance + +3.2 Download and install Ansible + +3.3 Create the folder for example /root/aws/ + +3.4 Copy all files from my folder /Ansible into your Ansible project (ansible.cfg, instance.yml, mykey.pem) + +mykey.pem you have to get using step 1.2 +# Start +4.1 Type the commands on your Terrafom instance: + + #cd /your folder + + #terraform plan + + #terraform apply + + #yes + +![ezcv logo](/images/aws.png) diff --git a/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Terraform/var.tf b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Terraform/var.tf new file mode 100644 index 0000000..6f1e65d --- /dev/null +++ b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Terraform/var.tf @@ -0,0 +1,18 @@ +variable "password" { + description = "pass for Ansible" + type = string + sensitive = true +} +variable "host"{ + description = "The IP of my Ansible" +} +variable "access" { + description = "my access_key for AWS" + type = string + sensitive = true +} +variable "secret" { + description = "my secret_key for AWS" + type = string + sensitive = true +}
\ No newline at end of file diff --git a/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Terraform/vyos.tf b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Terraform/vyos.tf new file mode 100644 index 0000000..8940ab5 --- /dev/null +++ b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/Terraform/vyos.tf @@ -0,0 +1,87 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 5.0" + } + } +} + +provider "aws" { + access_key = var.access + secret_key = var.secret + region = var.region +} + +variable "region" { + default = "us-east-1" + description = "AWS Region" +} + +variable "ami" { + default = "ami-**************" # ami image please enter your details + description = "Amazon Machine Image ID for VyOS" +} + +variable "type" { + default = "t2.micro" + description = "Size of VM" +} + +# my resource for VyOS + +resource "aws_instance" "myVyOSec2" { + ami = var.ami + key_name = "mykeyname" # Please enter your details + security_groups = ["my_sg"] # Please enter your details + instance_type = var.type + tags = { + name = "VyOS System" + } +} + +output "my_IP"{ +value = aws_instance.myVyOSec2.public_ip +} + + +#IP of aws instance copied to a file ip.txt in local system Terraform + +resource "local_file" "ip" { + content = aws_instance.myVyOSec2.public_ip + filename = "ip.txt" +} + +#connecting to the Ansible control node using SSH connection + +resource "null_resource" "SSHconnection1" { +depends_on = [aws_instance.myVyOSec2] +connection { + type = "ssh" + user = "root" + password = var.password + host = var.host +} +#copying the ip.txt file to the Ansible control node from local system + provisioner "file" { + source = "ip.txt" + destination = "/root/aws/ip.txt" # The folder of your Ansible project + } +} + +resource "null_resource" "SSHconnection2" { +depends_on = [aws_instance.myVyOSec2] +connection { + type = "ssh" + user = "root" + password = var.password + host = var.host +} +#command to run Ansible playbook on remote Linux OS +provisioner "remote-exec" { + inline = [ + "cd /root/aws/", + "ansible-playbook instance.yml" +] +} +} diff --git a/Terraform/AWS_terraform_ansible_single_vyos_instance-main/images/aws.png b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/images/aws.png Binary files differnew file mode 100644 index 0000000..c1c111b --- /dev/null +++ b/Terraform/AWS_terraform_ansible_single_vyos_instance-main/images/aws.png |