rearrange things, automate ansible inventory
This commit is contained in:
		
							parent
							
								
									299b142adc
								
							
						
					
					
						commit
						e2423e7e92
					
				
					 11 changed files with 32 additions and 33 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
										
									
									
										vendored
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					ansible/id_ed25519
 | 
				
			||||||
| 
						 | 
					@ -1,11 +1,5 @@
 | 
				
			||||||
# yatf
 | 
					# yatf
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## nginx setup on vms:
 | 
					 | 
				
			||||||
```bash
 | 
					 | 
				
			||||||
./mkinv 127.0.0.1 127.0.0.2
 | 
					 | 
				
			||||||
ansible-playbook nginx_setup.yml -i ./inventory.ini
 | 
					 | 
				
			||||||
```
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## doc links
 | 
					## doc links
 | 
				
			||||||
https://terraform-provider.yandexcloud.net/
 | 
					https://terraform-provider.yandexcloud.net/
 | 
				
			||||||
https://yandex.cloud/ru/docs/tutorials/infrastructure-management/terraform-quickstart
 | 
					https://yandex.cloud/ru/docs/tutorials/infrastructure-management/terraform-quickstart
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										6
									
								
								ansible/ansible.cfg
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								ansible/ansible.cfg
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					[defaults]
 | 
				
			||||||
 | 
					inventory = inventory.yml
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					remote_user = andrei
 | 
				
			||||||
 | 
					private_key_file = id_ed25519_yatf
 | 
				
			||||||
 | 
					host_key_checking = False
 | 
				
			||||||
							
								
								
									
										2
									
								
								ansible/inventory.yml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								ansible/inventory.yml
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,2 @@
 | 
				
			||||||
 | 
					plugin: cloud.terraform.terraform_provider
 | 
				
			||||||
 | 
					project_path: ../terraform
 | 
				
			||||||
							
								
								
									
										11
									
								
								mkinv
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								mkinv
									
										
									
									
									
								
							| 
						 | 
					@ -1,11 +0,0 @@
 | 
				
			||||||
#!/usr/bin/env bash
 | 
					 | 
				
			||||||
FILENAME="./inventory.ini"
 | 
					 | 
				
			||||||
A_USER="andrei"
 | 
					 | 
				
			||||||
A_KEY="$HOME/.ssh/id_ed25519_yatf"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
counter=0
 | 
					 | 
				
			||||||
echo -n > "$FILENAME"
 | 
					 | 
				
			||||||
for i; do
 | 
					 | 
				
			||||||
    echo "vm$counter ansible_host=$i ansible_user=$A_USER ansible_ssh_private_key_file=$A_KEY" >> "$FILENAME"
 | 
					 | 
				
			||||||
    ((counter++))
 | 
					 | 
				
			||||||
done
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,9 +0,0 @@
 | 
				
			||||||
output "lb-ip" {
 | 
					 | 
				
			||||||
  value = yandex_lb_network_load_balancer.balancer1.listener
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
output "vm-ips" {
 | 
					 | 
				
			||||||
  value = tomap({
 | 
					 | 
				
			||||||
    for name, vm in yandex_compute_instance.vm : name => vm.network_interface.0.nat_ip_address
 | 
					 | 
				
			||||||
  })
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -3,6 +3,9 @@ terraform {
 | 
				
			||||||
    yandex = {
 | 
					    yandex = {
 | 
				
			||||||
      source = "yandex-cloud/yandex"
 | 
					      source = "yandex-cloud/yandex"
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    ansible = {
 | 
				
			||||||
 | 
					      source = "ansible/ansible"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,6 +15,7 @@ provider "yandex" {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
resource "yandex_compute_instance" "vm" {
 | 
					resource "yandex_compute_instance" "vm" {
 | 
				
			||||||
  count = 2
 | 
					  count = 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  name = "vm${count.index}"
 | 
					  name = "vm${count.index}"
 | 
				
			||||||
  platform_id = "standard-v1"
 | 
					  platform_id = "standard-v1"
 | 
				
			||||||
  boot_disk {
 | 
					  boot_disk {
 | 
				
			||||||
| 
						 | 
					@ -47,14 +51,13 @@ resource "yandex_vpc_subnet" "subnet1" {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
resource "yandex_lb_target_group" "group1" {
 | 
					resource "yandex_lb_target_group" "group1" {
 | 
				
			||||||
  name = "group1"
 | 
					  name = "group1"
 | 
				
			||||||
  target {
 | 
					 | 
				
			||||||
    subnet_id = yandex_vpc_subnet.subnet1.id
 | 
					 | 
				
			||||||
    address = yandex_compute_instance.vm[0].network_interface.0.ip_address
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  target {
 | 
					  dynamic "target" {
 | 
				
			||||||
 | 
					    for_each = yandex_compute_instance.vm
 | 
				
			||||||
 | 
					    content {
 | 
				
			||||||
      subnet_id = yandex_vpc_subnet.subnet1.id
 | 
					      subnet_id = yandex_vpc_subnet.subnet1.id
 | 
				
			||||||
    address = yandex_compute_instance.vm[1].network_interface.0.ip_address
 | 
					      address = target.value.network_interface.0.ip_address
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -80,3 +83,13 @@ resource "yandex_lb_network_load_balancer" "balancer1" {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					resource "ansible_host" "vm" {
 | 
				
			||||||
 | 
					  count = length(yandex_compute_instance.vm)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  name = "vm${count.index}"
 | 
				
			||||||
 | 
					  groups = ["nginx"]
 | 
				
			||||||
 | 
					  variables = {
 | 
				
			||||||
 | 
					    ansible_host = yandex_compute_instance.vm[count.index].network_interface.0.nat_ip_address
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										3
									
								
								terraform/output.tf
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								terraform/output.tf
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,3 @@
 | 
				
			||||||
 | 
					output "lb-ip" {
 | 
				
			||||||
 | 
					  value = yandex_lb_network_load_balancer.balancer1.listener
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue