Hoatu Tere vm ESXi me Terraform

Tena koutou katoa, ko Ivan toku ingoa, he kaiwhakahaere punaha waipiro ahau (OPS).

E hiahia ana ahau ki te korero ki a koe me pehea taku tohatoha miihini mariko ki runga i te ESXi kaore he vCenter ma te whakamahi i a Terraform.

He maha tonu nga wa ka tukuna e koe nga miihini mariko hei whakamatautau i tenei, i tera tono ranei. Na te mangere, i whakaaro ahau ki te whakaaunoa i te mahi. Ko taku rapunga i arahina ahau ki tetahi hua whakamiharo mai i te kamupene hashicorp, terraform.

Ki taku whakaaro he maha nga tangata e mohio ana he aha te Terraform, engari ko te hunga kaore e mohio, he tono mo te whakahaere i tetahi kapua, hanganga, ratonga ranei ma te whakamahi i te kaupapa IasC (Hanganga hei waehere).

Ka whakamahi ahau i te ESXi hei taiao mariko. He tino ngawari, he watea me te pono.
Ka kite ahau i tetahi patai.

He aha te terraform mena ka taea e koe te whakamahi i te vCenter Server?

Ko te akoranga ka taea e koe, engari ... Tuatahi, he raihana taapiri tenei, tuarua, he tino whai rawa tenei hua karekau e uru ki runga i taku kaimau kaainga, tuatoru, he whai waahi ki te whakapai ake i o pukenga.

Ko te papaaa Intel NUC hei tūmau:

CPU: 2 CPUs x Intel(R) Core(TM) i3-4010U CPU @ 1.70GHz
RAM: 8Gb
HDD: 500Gb
ESXi version: ESXi-6.5.0-4564106-standard (VMware, Inc.)

Na, ko nga mea tuatahi i te tuatahi.

I tenei wa, me whirihora esxi, ara, whakatuwhera te tauranga VNC i nga tautuhinga papaahi.

Ma te taunoa, ka tiakina te konae. Ka mahia e matou nga manipulations e whai ake nei:

chmod 644 /etc/vmware/firewall/service.xml
chmod +t /etc/vmware/firewall/service.xml
vi /etc/vmware/firewall/service.xml

tāpirihia te paraka e whai ake nei ki te mutunga o te kōnae:

<service id="1000">
  <id>packer-vnc</id>
  <rule id="0000">
    <direction>inbound</direction>
    <protocol>tcp</protocol>
    <porttype>dst</porttype>
    <port>
      <begin>5900</begin>
      <end>6000</end>
    </port>
  </rule>
  <enabled>true</enabled>
  <required>true</required>
</service>

Ka puta matou ka penapena. Hurihia nga motika ka whakaara ano i te ratonga:

chmod 444 /etc/vmware/firewall/service.xml
esxcli network firewall refresh

Whai mana kia whakaara ano te kaihautu. Muri iho, me mahi ano tenei mahi raweke.

Mai i tenei wa ka mahia e ahau nga mahi katoa i roto i te miihini mariko i runga i te tūmau kotahi.

Te whakamahinga o nga hua:

OS: Centos 7 x86_64 minimal
RAM: 1GB
HDD: 20GB
Selinux: disable
firewalld: disable

I muri mai ka hiahia tatou packer, he hua ano na HashiCorp.

E hiahiatia ana ki te kohikohi aunoa i te ahua "koura". Ka whakamahia e tatou a muri ake nei.

yum install unzip git -y
curl -O https://releases.hashicorp.com/packer/1.5.5/packer_1.5.5_linux_amd64.zip
unzip packer_1.5.5_linux_amd64.zip -d /usr/bin && rm -rf packer_1.5.5_linux_amd64.zip
packer version
Packer v1.5.5

Kei te neke putanga packer Ka puta he hapa na te mea kei roto pea i a RedHat tetahi kete he rite te ingoa.

which -a packer
/usr/sbin/packer

Hei whakaoti i tenei, ka taea e koe te hanga hononga hono, te whakamahi ranei i tetahi ara tino /usr/bin/packer.

Inaianei me ovftool tikiake hononga. Tikiake, hoatu ki runga i te tūmau ka tāuta:

chmod +x VMware-ovftool-4.4.0-15722219-lin.x86_64.bundle
./VMware-ovftool-4.4.0-15722219-lin.x86_64.bundle
Extracting VMware Installer...done.
You must accept the VMware OVF Tool component for Linux End User
License Agreement to continue.  Press Enter to proceed.
VMWARE END USER LICENSE AGREEMENT
Do you agree? [yes/no]:yes
The product is ready to be installed.  Press Enter to begin
installation or Ctrl-C to cancel. 
Installing VMware OVF Tool component for Linux 4.4.0
    Configuring...
[######################################################################] 100%
Installation was successful.

Me haere tonu tatou.

I whakaritea e ahau nga mea katoa e hiahiatia ana e au mo te kiki.

git clone https://github.com/letnab/create-and-deploy-esxi.git && cd create-and-deploy-esxi

Ki te kōpaki nui me whakauru koe i te tohatoha punaha whakahaere. Ki taku take he centos 7.

Me whakatika ano koe i te konae centos-7-base.json:

variables: указать свои данные для подключения
iso_urls: указать актуальный
iso_checksum: чексумма вашего образа 

I muri i nga huringa katoa, whakahaerehia te hanga:

/usr/bin/packer build centos-7-base.json

Mena kua whirihorahia nga mea katoa ka tohua tika, ka kite koe i tetahi pikitia o te whakaurunga aunoa o te punaha whakahaere. E 7-8 meneti te roa o tenei mahi.

I muri i te otinga angitu i roto i te kōpaki putanga-packer-centos7-x86_64 ka puta he kōnae ova.

Tāuta Terraform:

curl -O https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_linux_amd64.zip
unzip terraform_0.12.24_linux_amd64.zip -d /usr/bin/ && rm -rf terraform_0.12.24_linux_amd64.zip
terraform version
Terraform v0.12.24

I te mea kaore he kaiwhakarato a Terraform mo ESXi, me hanga e koe tetahi.

Whakaritea haere:

cd /tmp
curl -O https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.14.2.linux-amd64.tar.gz && rm -rf go1.14.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
go version go1.14.2 linux/amd64

I muri mai, ka kohia e matou te kaiwhakarato:

go get -u -v golang.org/x/crypto/ssh
go get -u -v github.com/hashicorp/terraform
go get -u -v github.com/josenk/terraform-provider-esxi
export GOPATH="$HOME/go"
cd $GOPATH/src/github.com/josenk/terraform-provider-esxi
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-w -extldflags "-static"' -o terraform-provider-esxi_`cat version`
cp terraform-provider-esxi_`cat version` /usr/bin

Kei te raina mutunga matou. Me haere tatou ki te whakaputa i to tatou ahua.

Haere ki te kōpaki:

cd /root/create-and-deploy-esxi/centos7

Tuatahi, whakatikahia te konae taurangi.tf. Me tohu e koe he hononga ki te tūmau ESXi.

I roto i te kōnae network_config.cfg kei roto nga tautuhinga whatunga o te miihini mariko a meake nei. Ka hurihia e matou kia rite ki o maatau hiahia me te whakahaere i te raarangi kotahi:

sed -i -e '2d' -e '3i "network": "'$(gzip < network_config.cfg| base64 | tr -d 'n')'",' metadata.json

Na, i roto i te konae matua.tf Hurihia te ara ki te konae ova ki a koe, mena he rereke.

Ko te wa pono.

terraform init
Initializing the backend...

Initializing provider plugins...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.esxi: version = "~> 1.6"
* provider.template: version = "~> 2.1"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.template_file.Default: Refreshing state...
data.template_file.network_config: Refreshing state...

------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # esxi_guest.Default will be created
  + resource "esxi_guest" "Default" {
      + boot_disk_size         = (known after apply)
      + disk_store             = "datastore1"
      + guest_name             = "centos7-test"
      + guest_shutdown_timeout = (known after apply)
      + guest_startup_timeout  = (known after apply)
      + guestinfo              = {
          + "metadata"          = "base64text"
          + "metadata.encoding" = "gzip+base64"
          + "userdata"          = "base64text"
          + "userdata.encoding" = "gzip+base64"
        }
      + guestos                = (known after apply)
      + id                     = (known after apply)
      + ip_address             = (known after apply)
      + memsize                = "1024"
      + notes                  = (known after apply)
      + numvcpus               = (known after apply)
      + ovf_properties_timer   = (known after apply)
      + ovf_source             = "/root/create-and-deploy-esxi/output-packer-centos7-x86_64/packer-centos7-x86_64.ova"
      + power                  = "on"
      + resource_pool_name     = (known after apply)
      + virthwver              = (known after apply)

      + network_interfaces {
          + mac_address     = (known after apply)
          + nic_type        = (known after apply)
          + virtual_network = "VM Network"
        }
    }

Plan: 1 to add, 0 to change, 0 to destroy.

------------------------------------------------------------------------

Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.

Mutu:

terraform apply

Mena ka tika nga mea katoa, na i roto i nga meneti 2-3 ka tukuna he miihini mariko hou mai i te ahua o mua.

Ko nga whiringa mo te whakamahi i enei mea katoa he iti noa na to whakaaro.

I hiahia noa ahau ki te whakapuaki i taku wheako me te whakaatu i nga kaupapa matua i te wa e mahi ana me enei hua.

Mauruuru koe mo te aro!

PS: Ka harikoa ahau ki te whiwhi whakahē whai hua.

Source: will.com

Tāpiri i te kōrero