Hey Guys,
Thanks for the info. Let me clarify a bit.
I want to use test kitchen to test my chef cookbooks. I wanted to test my cookbooks on temporary servers that are spun up via terraform also by test kitchen.
I've got the terraform-kitchen plugin working, but if it is just for provisioning/testing terraform scripts it isn't of much value, because I don't need test kitchen for that.
I can do that with the standard terraform client. I wanted to have test kitchen execute both workflows.
- spin up temp server via terraform2 start up chef-zero and have test kitchen install chef client on new temp server and send cookbooks and execute them and tests.
The terraform chef provisioner requires a chef server. I've got that working also, but I wanted to bypass the need for the chef server and experiment with test kitchen and chef-zero.
In your solution below, how do the cookbooks get to the new client?
Dan-Joe
December 18 |
Hi There!
It looks like there is kitchen-terraform gem (GitHub - newcontext-oss/kitchen-terraform: Test Kitchen plugins for testing Terraform configurations), but that appears to be for testing your terraform scripts. On the terraform side, the chef provisioner only supports a server installation, so using test-kitchen to test that would not be useful.
What is unclear for me about your question, is the ultimate goal. Are you wanting to find a way to use terraform without a chef-server, or a way to use test kitchen to test your terraform scripts?
Assuming the former, I have run into the same problem. What I did was the following:
• Set userdata in the instance resource to set the admin password (for windows)
• Create a project Berksfile and use the null_resource with the file provisioners to copy it to the instance (using the admin password I set in userdata)
• Use a null resource with the remote-exec provisioner to
o Install the chef-client, berks, and git
o Resolve and verndor the berksfile
o Run the chef-client with the desired runlist
Here is what that last part looks like:
Bootstrap and provision the instance
resource "null_resource" "Run_Chef" {
count = "${ var.server_count }"
depends_on = ["null_resource.put_files"]
connection {
host = "${element(openstack_networking_floatingip_v2.get_corp_ip.*.address, count.index)}"
type = "winrm"
user = "Administrator"
password = "${ var.admin_pass }"
insecure = true
}
provisioner "remote-exec" {
inline = [
"powershell -Command ". { iwr -useb https://omnitruck.chef.io/install.ps1 } | iex; install -version ${ var.chef_client_version } ",
"powershell -Command ". iwr -useb https://github.com/git-for-windows/git/releases/download/v2.14.1.windows.1/Git-2.14.1-64-bit.exe -OutFile C:\chef\repo\git_installer.exe ",
"c:\chef\repo\git_installer.exe /SILENT /COMPONENTS="icons,ext\reg\shellhere,assoc,assoc_sh"",
"set path=%path%;c:\opscode\chef\bin\;c:\opscode\chef\embedded\bin\;C:\Program Files\Git\cmd\",
"set git_ssl_no_verify=true",
"setx path %path%",
"cmd /c "gem install berkshelf && exit"",
"cmd /c "berks vendor c:\chef\repo\cookbooks -b c:\chef\repo\Berksfile && exit"",
"chef-client --local-mode -r recipe[${ var.cookbook }::${ var.recipe }] --config-option cookbook_path=c:\chef\repo\cookbooks""
]
}
Note that the script (for windows) includes some “magic” lines where the actualy command is wrapped in "cmd /c "&& exit"". This is because bers returns an unexpected exit code that terminates the remote-exec connection. The wrapper ensures a proper exit code so that the execution continues.
Kind regards,
Dan-Joe Lopez
Visit Topic or reply to this email to respond.
You are receiving this because you enabled mailing list mode.
To unsubscribe from these emails, click here.