在本文中,我们将介绍如何安装Terraform oVirt提供程序插件并使用它来自动化oVirt/RHEV虚拟化环境操作。注:Terraform oVirt提供程序用于与oVirt支持的许多资源进行交互。
一、安装Go参考文章 我们将从源代码构建插件,为此,我们需要在本地工作站上安装Go(Golang),参考以下文章: 在CentOS 8系统中下载和安装Go 1.13.4的方法。 在Debian 10 Linux上下载安装Go及测试安装Go是否可用的方法。 在Fedora系统中安装Go及编写Go中的第一个程序、使用Go模块。
二、安装Terraform参考文章 oVirt terraform提供程序要求在完成构建的机器上安装Terraform,参考在Linux操作系统中下载及安装Terraform 0.12.3的方法,可以安装v0.12.12版本。 检查版本的命令: $ terraform version 返回信息为如下表示安装成功: Terraform v0.12.12
三、构建oVirt Terraform插件 现在,我们为Terraform构建oVirt插件,但是首先,从Git克隆项目源: mkdir -p $HOME/terraform-providers/ cd $HOME/terraform-providers/ git clone https://github.com/oVirt/terraform-provider-ovirt.git 要编译提供程序,请运行: cd terraform-provider-ovirt make build 这将构建提供程序并将提供程序二进制文件放入$GOPATH/bin目录中,输出如下所示: ==> Checking that code complies with gofmt requirements... go install go: downloading github.com/hashicorp/terraform v0.12.2 go: downloading github.com/ovirt/go-ovirt v4.3.4+incompatible go: extracting github.com/ovirt/go-ovirt v4.3.4+incompatible go: extracting github.com/hashicorp/terraform v0.12.2 go: downloading github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f go: downloading github.com/zclconf/go-cty v0.0.0-20190516203816-4fecf87372ec go: downloading github.com/hashicorp/logutils v1.0.0 go: downloading github.com/hashicorp/go-plugin v1.0.1-0.20190610192547-a1bc61569a26 go: downloading github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db go: downloading github.com/hashicorp/hcl2 v0.0.0-20190515223218-4b22149b7cef go: downloading github.com/hashicorp/terraform-config-inspect v0.0.0-20190327195015-8022a2663a70 go: downloading github.com/hashicorp/go-version v1.1.0 go: extracting github.com/hashicorp/logutils v1.0.0 go: downloading github.com/mitchellh/mapstructure v1.1.2 go: extracting github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db go: extracting github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f go: downloading github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590 go: extracting github.com/hashicorp/go-version v1.1.0 go: downloading github.com/hashicorp/go-getter v1.3.0 go: extracting github.com/hashicorp/terraform-config-inspect v0.0.0-20190327195015-8022a2663a70 go: extracting github.com/hashicorp/go-plugin v1.0.1-0.20190610192547-a1bc61569a26 go: downloading github.com/agext/levenshtein v1.2.2 go: extracting github.com/zclconf/go-cty v0.0.0-20190516203816-4fecf87372ec go: extracting github.com/mitchellh/mapstructure v1.1.2 go: downloading github.com/mitchellh/cli v1.0.0 go: extracting github.com/agext/levenshtein v1.2.2 go: downloading github.com/hashicorp/go-uuid v1.0.1 go: downloading github.com/davecgh/go-spew v1.1.1 go: extracting github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590 go: extracting github.com/hashicorp/go-uuid v1.0.1 go: downloading github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f go: extracting github.com/mitchellh/cli v1.0.0 go: downloading github.com/hashicorp/go-multierror v1.0.0 go: downloading github.com/posener/complete v1.2.1 go: extracting github.com/hashicorp/go-getter v1.3.0 go: extracting github.com/davecgh/go-spew v1.1.1 go: downloading github.com/hashicorp/go-cleanhttp v0.5.0 go: extracting github.com/hashicorp/go-multierror v1.0.0 go: extracting github.com/posener/complete v1.2.1 go: downloading github.com/vmihailenco/msgpack v4.0.1+incompatible go: downloading github.com/fatih/color v1.7.0 go: downloading github.com/mattn/go-isatty v0.0.5 go: extracting github.com/hashicorp/go-cleanhttp v0.5.0 go: downloading github.com/hashicorp/go-safetemp v1.0.0 go: extracting github.com/mattn/go-isatty v0.0.5 go: downloading github.com/aws/aws-sdk-go v1.19.18 go: extracting github.com/hashicorp/go-safetemp v1.0.0 go: extracting github.com/vmihailenco/msgpack v4.0.1+incompatible go: extracting github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f go: downloading google.golang.org/grpc v1.18.0 go: extracting github.com/hashicorp/hcl2 v0.0.0-20190515223218-4b22149b7cef go: downloading github.com/bgentry/speakeasy v0.1.0 go: extracting github.com/bgentry/speakeasy v0.1.0 go: downloading github.com/armon/go-radix v1.0.0 go: extracting github.com/armon/go-radix v1.0.0 go: downloading cloud.google.com/go v0.36.0 go: downloading github.com/spf13/afero v1.2.1 go: downloading github.com/hashicorp/errwrap v1.0.0 go: downloading github.com/oklog/run v1.0.0 go: extracting github.com/oklog/run v1.0.0 go: downloading github.com/mitchellh/reflectwalk v1.0.0 go: extracting github.com/hashicorp/errwrap v1.0.0 go: downloading github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d go: extracting github.com/mitchellh/reflectwalk v1.0.0 go: downloading github.com/mitchellh/go-homedir v1.0.0 go: extracting github.com/spf13/afero v1.2.1 go: extracting github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d go: downloading google.golang.org/api v0.1.0 go: downloading github.com/mitchellh/go-testing-interface v1.0.0 go: extracting github.com/mitchellh/go-homedir v1.0.0 go: extracting github.com/mitchellh/go-testing-interface v1.0.0 go: downloading github.com/mitchellh/go-wordwrap v1.0.0 go: extracting github.com/mitchellh/go-wordwrap v1.0.0 go: downloading golang.org/x/net v0.0.0-20190502183928-7f726cade0ab go: extracting github.com/fatih/color v1.7.0 go: downloading github.com/apparentlymart/go-textseg v1.0.0 go: extracting github.com/apparentlymart/go-textseg v1.0.0 go: downloading github.com/mattn/go-colorable v0.1.1 go: extracting github.com/mattn/go-colorable v0.1.1 go: downloading github.com/zclconf/go-cty-yaml v0.1.0 go: extracting github.com/zclconf/go-cty-yaml v0.1.0 go: extracting google.golang.org/grpc v1.18.0 go: downloading google.golang.org/genproto v0.0.0-20190201180003-4b09977fb922 go: downloading golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 go: extracting golang.org/x/net v0.0.0-20190502183928-7f726cade0ab go: downloading github.com/google/go-cmp v0.3.0 go: extracting golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 go: extracting github.com/google/go-cmp v0.3.0 go: downloading github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb go: extracting github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb go: downloading github.com/golang/protobuf v1.3.0 go: downloading github.com/apparentlymart/go-cidr v1.0.0 go: extracting github.com/apparentlymart/go-cidr v1.0.0 go: downloading github.com/blang/semver v3.5.1+incompatible go: extracting github.com/blang/semver v3.5.1+incompatible go: extracting cloud.google.com/go v0.36.0 go: extracting github.com/golang/protobuf v1.3.0 go: downloading github.com/mitchellh/copystructure v1.0.0 go: extracting github.com/mitchellh/copystructure v1.0.0 go: extracting google.golang.org/genproto v0.0.0-20190201180003-4b09977fb922 go: downloading go.opencensus.io v0.18.0 go: extracting go.opencensus.io v0.18.0 go: extracting google.golang.org/api v0.1.0 go: extracting github.com/aws/aws-sdk-go v1.19.18 go: downloading github.com/mitchellh/hashstructure v1.0.0 go: downloading github.com/ulikunitz/xz v0.5.5 go: downloading golang.org/x/text v0.3.2 go: downloading golang.org/x/oauth2 v0.0.0-20190220154721-9b3c75971fc9 go: extracting github.com/mitchellh/hashstructure v1.0.0 go: extracting golang.org/x/oauth2 v0.0.0-20190220154721-9b3c75971fc9 go: downloading github.com/googleapis/gax-go v2.0.0+incompatible go: extracting github.com/googleapis/gax-go v2.0.0+incompatible go: downloading github.com/googleapis/gax-go/v2 v2.0.3 go: extracting github.com/googleapis/gax-go/v2 v2.0.3 go: downloading golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 go: extracting github.com/ulikunitz/xz v0.5.5 go: downloading github.com/satori/go.uuid v1.2.0 go: downloading github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af go: extracting github.com/satori/go.uuid v1.2.0 go: extracting github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af go: extracting golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 go: extracting golang.org/x/text v0.3.2 go: finding github.com/hashicorp/terraform v0.12.2 go: finding github.com/ovirt/go-ovirt v4.3.4+incompatible go: finding github.com/hashicorp/errwrap v1.0.0 go: finding github.com/hashicorp/go-multierror v1.0.0 go: finding github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f go: finding github.com/davecgh/go-spew v1.1.1 go: finding github.com/hashicorp/hcl2 v0.0.0-20190515223218-4b22149b7cef go: finding github.com/hashicorp/logutils v1.0.0 go: finding github.com/agext/levenshtein v1.2.2 go: finding github.com/mitchellh/copystructure v1.0.0 go: finding github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590 go: finding github.com/mitchellh/mapstructure v1.1.2 go: finding github.com/hashicorp/go-uuid v1.0.1 go: finding github.com/zclconf/go-cty v0.0.0-20190516203816-4fecf87372ec go: finding github.com/hashicorp/go-plugin v1.0.1-0.20190610192547-a1bc61569a26 go: finding github.com/apparentlymart/go-textseg v1.0.0 go: finding github.com/hashicorp/go-version v1.1.0 go: finding github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f go: finding github.com/mitchellh/reflectwalk v1.0.0 go: finding github.com/hashicorp/go-cleanhttp v0.5.0 go: finding github.com/mitchellh/go-wordwrap v1.0.0 go: finding github.com/hashicorp/go-getter v1.3.0 go: finding golang.org/x/text v0.3.2 go: finding github.com/apparentlymart/go-cidr v1.0.0 go: finding golang.org/x/net v0.0.0-20190502183928-7f726cade0ab go: finding github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db go: finding github.com/blang/semver v3.5.1+incompatible go: finding github.com/golang/protobuf v1.3.0 go: finding github.com/hashicorp/terraform-config-inspect v0.0.0-20190327195015-8022a2663a70 go: finding google.golang.org/grpc v1.18.0 go: finding github.com/spf13/afero v1.2.1 go: finding github.com/google/go-cmp v0.3.0 go: finding cloud.google.com/go v0.36.0 go: finding github.com/vmihailenco/msgpack v4.0.1+incompatible go: finding github.com/mitchellh/cli v1.0.0 go: finding github.com/mitchellh/go-homedir v1.0.0 go: finding github.com/zclconf/go-cty-yaml v0.1.0 go: finding github.com/aws/aws-sdk-go v1.19.18 go: finding github.com/mitchellh/hashstructure v1.0.0 go: finding golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 go: finding github.com/googleapis/gax-go/v2 v2.0.3 go: finding google.golang.org/genproto v0.0.0-20190201180003-4b09977fb922 go: finding github.com/armon/go-radix v1.0.0 go: finding github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d go: finding google.golang.org/api v0.1.0 go: finding go.opencensus.io v0.18.0 go: finding github.com/bgentry/speakeasy v0.1.0 go: finding github.com/fatih/color v1.7.0 go: finding github.com/hashicorp/go-safetemp v1.0.0 go: finding github.com/mattn/go-isatty v0.0.5 go: finding github.com/posener/complete v1.2.1 go: finding github.com/mitchellh/go-testing-interface v1.0.0 go: finding golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 go: finding github.com/ulikunitz/xz v0.5.5 go: finding github.com/mattn/go-colorable v0.1.1 go: finding github.com/satori/go.uuid v1.2.0 go: finding github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af go: finding golang.org/x/oauth2 v0.0.0-20190220154721-9b3c75971fc9 go: finding github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb go: finding github.com/oklog/run v1.0.0 检查创建的二进制文件: $ ls $GOPATH/bin/terraform-provider-ovirt /home/jmutai/go/bin/terraform-provider-ovirt
四、使用oVirt terraform provider 创建terraform provider目录: mkdir ~/.terraform.d/plugins 将提供程序二进制文件复制到创建的插件目录: cp $GOPATH/bin/terraform-provider-ovirt ~/.terraform.d/plugins 基本单位是创建提供程序配置文件: $ vim main.tf provider "ovirt" { username = "username@profile" url = "https://ovirt/ovirt-engine/api" password = "Password" } 支持以下参数: url–(必需)oVirt引擎API URL,如果省略,则使用OVIRT_URL环境变量。 username–(必填)用于访问oVirt引擎API的用户名,如果省略,则使用OVIRT_USERNAME环境变量。 password–(必需)用于访问oVirt引擎API的用户密码,如果省略,则使用OVIRT_PASSWORD环境变量。 放置创建文件后,运行以下命令对其进行初始化: $ terraform init
初始化成功,你可以开始使用插件自动化oVirt/RHEL虚拟化管理。
相关主题 |