Я использую terraform в DevOps Azure, конвейерах Azure Release.Конечная цель - раскрутить виртуальную машину, установить и запустить Ansible, чтобы мы могли запускать playbook для настройки только что настроенного сервера Windows.
Однако я получаю сообщение об ошибке:
2019-04-30T14:27:13.9975581Z [0m[0mazurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Connecting to remote host via SSH...
2019-04-30T14:27:13.9976968Z azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Host: 10.112.4.11
2019-04-30T14:27:13.9977790Z azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): User: scmadmin
2019-04-30T14:27:13.9978268Z azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Password: false
2019-04-30T14:27:13.9979371Z azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Private key: true
2019-04-30T14:27:13.9979804Z azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): SSH Agent: false
2019-04-30T14:27:13.9980255Z azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Checking Host Key: false
2019-04-30T14:27:21.1740015Z [0m[1mazurerm_virtual_machine.tf-vm-erx-builds: Still creating... (7m20s elapsed)[0m[0m
2019-04-30T14:27:31.1743030Z [0m[1mazurerm_virtual_machine.tf-vm-erx-builds: Still creating... (7m30s elapsed)[0m[0m
2019-04-30T14:27:32.9964209Z [31m
2019-04-30T14:27:32.9965326Z [1m[31mError: [0m[0m[1mError applying plan:
2019-04-30T14:27:32.9965547Z
2019-04-30T14:27:32.9965890Z 1 error(s) occurred:
2019-04-30T14:27:32.9966284Z
2019-04-30T14:27:32.9966897Z * azurerm_virtual_machine.tf-vm-erx-builds: timeout - last error: dial tcp 10.112.4.11:22: i/o timeout
Однако , если я запускаю тот же код terraform из Виртуальной машины, из которой я сгенерировал открытый и закрытый ключ, это работает как чудо.Пожалуйста, посмотрите вывод ниже.
azurerm_virtual_machine.tf-vm-erx-builds: Provisioning with 'remote-exec'...
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Connecting to remote host via SSH...
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Host: 10.112.4.11
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): User: scmadmin
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Password: false
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Private key: true
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): SSH Agent: true
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Checking Host Key: false
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Connected!
azurerm_storage_account.tf-sa-erx-builds: Still creating... (2m40s elapsed)
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Loaded plugins: fastestmirror, langpacks
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): epel-release-lat | 15 kB 00:00
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Examining /var/tmp/yum-root-j6a5hG/epel-release-latest-7.noarch.rpm: epel-release-7-11.noarch
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Marking /var/tmp/yum-root-j6a5hG/epel-release-latest-7.noarch.rpm to be installed
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): Resolving Dependencies
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): --> Running transaction check
azurerm_virtual_machine.tf-vm-erx-builds (remote-exec): ---> Package epel-release.noarch 0:7-11 will be installed
os_profile_linux_config {
disable_password_authentication = true
ssh_keys {
path = "/home/scmadmin/.ssh/authorized_keys"
key_data = cat id_rsa.pub
}
}
provisioner "remote-exec" {
inline = [
"sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y",
"sudo yum update -y",
"sudo yum install git -y",
"git clone https://'${var.git_username}':'${var.git_pat}'@'${var.git_url}'",
"cd erxpreprd",
"sudo yum install ansible -y",
"sudo yum -y install python-pip",
"sudo pip install pywinrm",
"ansible all -vvv -i inventory/hosts -m win_ping",
"ansible-playbook -vvv -i inventory/hosts playbooks/common.yml",
"ansible-playbook -vvv -i inventory/hosts playbooks/apply-failoverclustering.yml"
]
connection {
type = "ssh"
user = "${var.username}"
private_key = "${file("${var.private_key}")}" # private key id_rsa file
}
}
}
Не уверен, в чем проблема и как ее устранить.
Одна вещь, которую я вижу, - в Azure DevOps запустить SSH Agent: false где какна моей локальной виртуальной машине запустите SSH: Агент: true
Я добавил код: agent="true"
в блок connection , но он дал мне несколько других ошибок.PS: NSG выглядит следующим образом:
resource "azurerm_network_security_group" "tf-nsg-erx-buildserver" {
name = "${var.buildserver_nsg}"
location = "${data.azurerm_resource_group.tf-rg-erx-external.location}"
resource_group_name = "${data.azurerm_resource_group.tf-rg-erx-external.name}"
}
resource "azurerm_network_security_rule" "tf-nsr-erx-buildserver-22" {
name = "Open Port 22"
priority = 106
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "22"
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = "${data.azurerm_resource_group.tf-rg-erx-external.name}"
network_security_group_name = "${azurerm_network_security_group.tf-nsg-erx-buildserver.name}"
}
Теперь, используя NSG к сетевому интерфейсу, как показано ниже:
resource "azurerm_network_interface" "tf-ni-erx-builds" {
name = "${var.builds_base_hostname}${format("%02d",count.index+1)}-nic01"
location = "${data.azurerm_resource_group.tf-rg-erx-external.location}"
resource_group_name = "${data.azurerm_resource_group.tf-rg-erx-external.name}"
network_security_group_id = "${azurerm_network_security_group.tf-nsg-erx-buildserver.id}"
ip_configuration {
name = "${var.builds_base_hostname}${format("%02d",count.index+1)}-iip01"
subnet_id = "${azurerm_subnet.tf-sn-erx-builds.id}"
private_ip_address_allocation = "static"
private_ip_address ="10.112.4.${count.index+11}"
}
}
И, наконец, ссылка на сетевой интерфейс в блоке создания виртуальной машины, как показано ниже:
resource "azurerm_virtual_machine" "tf-vm-erx-builds" {
name = "${var.builds_base_hostname}${format("%02d",count.index+1)}"
location = "${data.azurerm_resource_group.tf-rg-erx-external.location}"
resource_group_name = "${data.azurerm_resource_group.tf-rg-erx-external.name}"
network_interface_ids = ["${element(azurerm_network_interface.tf-ni-erx-builds.*.id, count.index)}"]
vm_size = "${var.builds_vm_size}"
Хотелось бы, чтобы все выполнялись из DevOs Azure