Custom Ansible Module - Info or Facts? - module

I have a VMware vCenter with several VMs. I want to use ansible to configure the network interfaces of the guest based on the network to which the VMware network interface is connected. Since the network interface names in the guest may not be named in a stable way, I want to match it based on the mac-address, which is known inside and outside the VM.
For that I want to gather information from VMware vCenter for each VM, which leads to the first question: Since the needed information is tightly coupled to the VM, should I write a *_facts (and no *_info) module for that?
Since this module code directly contacts the vCenter API, there is no need to execute the code on the target host, which leads to the 2nd question: Is there a way to always execute a module locally? (Without using delegate_to in the playbook)
And the last question: Is it possible to execute *_facts modules automatically, without explicitly referencing them in a playbook?

Related

Using saltstack ssh

Is there a difference between using salt-proxy ssh and directly salt-ssh? I'm interested because according to documentation both aimed to run remote commands without agent installation on the end machine.
You cant simply do salt-ssh on a proxy minion, for which you would have to write your own custom ssh interface to the remote system, because your proxy minion may not support doing salt-ssh.
How to choose between using salt-ssh vs salt-proxy totally depends on the type of a minion system.
As stated in the saltstack documentation - https://docs.saltstack.com/en/latest/topics/ssh/index.html and
https://docs.saltstack.com/en/latest/topics/proxyminion/index.html
For salt-ssh to be used, the remote system must have python installed - one of the criteria. For example, controlling ubuntu from centos.
As stated in the salt-proxy doc,
Proxy minions are a developing Salt feature that enables controlling
devices that, for whatever reason, cannot run a standard salt-minion.
Examples include network gear that has an API but runs a proprietary
OS, devices with limited CPU or memory, or devices that could run a
minion, but for security reasons, will not.

Set static IP in ESXi VM

Setup:
I have a setup with several ESXi 5.5 hypervisors (paid licenses) and a vCenter 6.0 linux server instance. I don't have any other infrastructure like vCloud, workstation, etc. I'm using ovftool to deploy a VM from an OVF template. The template that I deploy has no IP configuration when it starts up.
What I'm trying to do:
Automatically configure a static IP address, mask, and gateway through some scripted means. I haven't found a feasible way to do this with ovftool itself.
Requirements:
It cannot use DHCP. This infrastructure is not set up in our network and it is not feasible to do so.
It must be run in a remote Linux machine, within the command line of the hypervisor, or within the command line of vCenter.
It must be a production supported approach (no hacks).
Besides that, I don't really care what language is used to do it. Something ordinary like bash, python, c, java, perl, etc is preferable over something obscure.
If an interface is mentioned (like an API), please note the specific functions that can carry out this operation rather than just saying "oh this interface can/should be able to do that".

Can a process running inside a virtual machine get information on processes running outside the virtual machine?

Lets say I am running Windows 7 with two major processes I will call V and P.
V is a virtual machine running another instance of Windows 7, while P is the process that I want information about and both are on the 'top-level' operating system.
Can a process, C, which is being run by the Windows 7 inside V, get information about processes such as P from within V? In other words, can a process being run inside a virtual machine get any information about processes being run by the operating system which is also maintaining the virtual machine process? I feel like it would rely on the ability of the virtual machine process, if it is not programmed to specifically retrieve such information then it will not be possible.
I have read another topic about the difficulty of even detecting whether a process is being run by a virtual machine or not. Some feel it is not reliable or possible. I am not sure that there is a standard way to find this out yet, I believe the post was roughly 4 or 5 years ago.
So can this be done by process C, or will there need to be more standard routines to accomplish this task?
I don't believe it's possible for an operating system running under a virtual machine manager (e.g. (VMWare et al) to directly access information relating to the host operating system because by default most virtual machine managers attempt to fully isolate the host and guest systems.
That being said most virtual machine managers have mechanisms which allow the virtual machine to share data and communicate with the host system. By using these mechanisms it is possible for the host operating system to convey information about itself to the guest.
Option 1: A shared file
With shared networking between the host and the guest it would be possible to have the host system write the information to a file in the shared location and have the guest open and parse this file using CreateFile and a UNC path e.g. \\host\sharename\file.txt
Option 2: Data transfer via a socket or named pipe
Shared networking between the host and the guest would allow you to use the Windows Sockets or Named Pipe APIs to create TCP or UDP sockets, or a named pipe through which data can be exchanged.
This approach would involve a server application running on the host application, which writes the process information you're after to the socket or pipe, where it can be read by the guest system which runs a client process.
Option 3: Remote Windows Management Instrumentation (WMI) Query
WMI provides a standard means of getting information and interacting with many aspects of the windows operating system including information about processes.
This is probably the most complex option because by default WMI does not accept queries from remote hosts (ie. your VM), so the host machine would need to be configured to allow remote WMI queries.
Once configured WMI is easily usable via the WMI command line client (wmic.exe) so you could invoke it with a query like this:
In this example:
%HOST_NAME% Is the name of the system hosting your Windows 7 VM
%TARGET_PROCESS% is the process name of the process you want
information about
wmi \node:%HOST_NAME% process where name='%TargetProcess%' get executablepath
This particular query gets the executable path of %TargetProcess% but there are many more properties available as per the documentation for the Win32_Process WMI Class documentation1.
Option 4: Shared clipboard
Some virtual machine managers allow the guest system to access the host's clipboard so information can be exchanged between applications running on the guest and host.
I appreciate it's probably the least conventional option but you could conceivably use the Windows Clipboard API to write the process info to the host's clipboard, and then read the information into a process on the guest system.
1NB:Although the Win32_Process class documentation lists properties in title case (ExecutablePath) I found they only worked properly in a wmic query when written in all lower case (executablepath)

How to maintain Selenium Grid?

I have many VMs which are used as part of Grid. Some as RC and some as Hub. Due to the large number of VMs that is being used, it is a big task to maintain the grid now. To change the RC to point to a different hub, I will have to
login to that machine
kill the current RC
run the java command again with a different hub URL
Yes, I can use a batch script to restart all the machines. But what if I just want to change just one machine?
Is it possible to create an application using JAVA RMI which can run the required commands to kill, start, restart the RCs or Hub? Has anyone ever tried to create such an application?
you should have a look at selenium grid2.0. It's been designed with exactly what you ask in mind.
You can create your own proxy extending either the selenium1 ( RC ) or selenium2 ( webdriver protocol ), and implement a list of interfaces that will allow to react to certain events.
You could for instance :
have one unique hub controlling all the nodes and refine the routing by implementing the matcher.
update the grid console to have some "reconfigure node" functionality directly there
add some rules on each node, for instance restart the VM and the server within it automatically every X test or when a specific event is detected.
I wouldn't start a RMI based solution. If you have VMs, you should have access to the VM API for the solution you choose, and you can use that to revert to a known clean state and restart from there each time. That will ensure you don't have left over crashed browsers and things like that.
thanks,
François
i know this is old question. How about setting puppet on your VM so you just need to specify one config on master.

How to simulate a large network of machines for testing?

Currently, I am writing an application that utilizes WMI to scan all the computers on our Active Directory network.
I'm interested in testing the program against all flavors of Windows machines in a testing environment.
Is there a way to similuate this environment in VMware or something?
Any ideas?
VMWare works well and can host many virtual computers on a single physical computer. You can also put the virtual computers on your active directory network.
If your goal is to set up a separate large network for testing that has it's own AD server you can look into Amazon EC2 for testing. The advantage here is once you setup your set of servers, you can turn them on and off as needed and only pay for the time actually used ($0.12 per hour).
http://aws.amazon.com/
You can use network simulation: http://en.wikipedia.org/wiki/Network_simulation
and good GPL tool is http://www.nsnam.org/
You have two options.
You probably have it right, with VMWare this is easy, try looking for cloning tools. If you plan on copying and pasting the image, you will get several problems (computer Guids repeated, Network Computer Names repeated, etc)
You can also "mock" the WMI response by wrapping the WMI methods that you want to call and implementing an interface, using Rhino Mock or NMock if you are working in .NET (which I assume you are).