Chef and Azure: learn.chef.io

I had not looked at the Chef docs for some time. They continue to be excellent. I was using them to see how deploying to Azure differed from a more on-premise VM. As far as I could see, the only difference was making sure that you had enabled the 80,5985 and 443 endpoints/ports in the Azure Portal. No amount of opening firewall ports on the provisioned VM will help if you have not done that.

I also suggest getting things working with the simplest possible test, and making network calls within a single server to start (I know what I mean hopefully you do, too late to explain more šŸ™‚ )

I left comments here and here.

A very helpful post on WinRm and networking difficulties here.

Easiest way to get non-truncated history, btw (hm not so sure now):

h | select -Property CommandLine -unique > x.txt

Session edits.

 

 

Advertisements

PowerShell DSC: deleting a Windows Service

This is simple and it works – thanks DSC. Code is here.

I want to declaratively delete a Windows Service… I tell it what I want, it figures out how. Part of that is not involving me in interactive decisions about what to do if it is already Absent, to use the Service provider keyword. I have saidĀ the required state is Absent, just make it so.

I decided that the Fax service was one I would never need, so that is my test case. As ever with actions against Windows Services, make sure the Services dialog is closed when you perform the action, else it will just hang.

The code to achieve that is immediately below the service dialog.

That is then compiled into MOF format (the . .\ServiceManager.ps1 screenshot), and then we execute (Start-DscConfiguration…). Net result is no Fax Service in Services after this.


Chef does not currently have the ability to delete a Windows Service, as far as I can see here.

Chef: more

If I try to apply an example from the bottom of this page… then it’s pretty clear this content will not fly on Windows (but will of course on Unix/Linux). But it’s still interesting to see errors. I’ll include this in a .rb file..

file 'C:\temp\settings.ini' do
  owner 'root'
  group 'root'
  mode '0755'
  action :create
end

, and then run it:
ChefError01

No mapping between account names and security IDs was done.

OK, so I've played with some permutations on this, and I see that this  works:

DenChefOwner01 DenChefOwner02
, and if I deliberately give it a bad owner, then more or less we get this again:

ChefError01

so the catch-all for bad anything almost is the "Mapping" exception. So we'll back in the valid user and make them the Group as well, just as a quck test:
ChefUser01 ChefUser02


That is ok, so now let's apply the group and user exactly as they are in Computer Management:

ChefUser03 ChefUser04
Enough for now.

.

.

Azure: Visual Studio Code performance… and Chef

Today at work, I did a demo of Chef running on Azure. It went badly despite my rehearsal in the morning: Visual Studio Code, which I like when running on my laptop, seemed a nice lightweight choice as the editor. During the demo the server was clearly suffering, so much so I even struggled to bring up the Task Manager. I should at least mention the configuration. This is it:

VMSpec01 VMSpec02

So not mega-brilliant, but for the little it was being asked to do, quite reasonable I thought. And it has an (Azure) SSD. Check this out then: cpu effectively sitting at 100% just after I start VSC, and going back to idle just after I exit:

VisualCodeHog01

VisualCodeHog03

VisualCodeHog02

 

VisualCodeHog04

Wha??!!!

Also, this is on Windows Server 2016 evaluation as you see from the screenshot above. Now let’s see how VSC behaves on a VM (admittedly a desktop) Ā running Windows 8.1 Enterprise:

This is the setup:

Windows81Azure0 Windows81Azure1

I installed and started VSC… and it was very quick, and didn’t use any CPU, well:

 

Windows81Azure2

Here we see that although there are a number of instances, they are each at 1%, worst case. And the editor is entirely usable:

Windows81Azure4

Lesson for me: don’t use VSC on a Windows Server, or at least 2016. As a parting shot, let’s see if Brackets behaves OK on the 2016 server.

And that’s fine, defined as CPU goes up at the point of installation, and then goes back to idle, give or take:

Windows81Azure5

So I’ll run the .rb with this content, as per the Chef website…

powershell_script 'Install IIS' do
 code 'Add-WindowsFeature Web-Server'
 guard_interpreter :powershell_script
 not_if "(Get-WindowsFeature -Name Web-Server).Installed"
 end
service 'w3svc' do
 action [:enable, :start]
 end
file 'c:\inetpub\wwwroot\Default.htm' do
 content '<html>
 <body>
 <h1>hello world</h1>
 </body>
 </html>'
 end

Looking at the diagnostics in the output below, then we see that Install IIS, and the 2 w3svc commands, are skipped over, but the file does not exist, so Chef creates it, and confirms the content:

BracketsOk01

If I now point at the location of the created page:

helloworld01

Enough.

 

Chef: Starting over

By chance, by Google, I finally landed on a Good tutorial area on Chef, which I managed to avoid seeing for the bulk of the day, namely Chef’s own tutorial site [https://learn.chef.io/tutorials/]

So gathering up the points from the day:

  • Get an Azure VM – forget the supplied one, too slow (please make sure it’s Windows Server 2012R2 or higher, to avoid PowerShell pain)
  • Download the Chef DKĀ to the VM, and install (installation takes a LONG time)
  • Also download Visual Studio Code, Notepad++, or some other decent editor
  • Check that Chef can be called from PowerShell as admin using [chef-apply -h]
  • Follow the basics for creating and using a file Resource, and a RecipeĀ here
  • Follow the basics for creating and using a serviceĀ ResourceĀ here
  • Follow the basics for creating a Cookbook here