Set static IP in ESXi VM - automation

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".

Related

Custom Ansible Module - Info or Facts?

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?

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.

Configuring Development Environments

If the development environment is run on the host, is there a fast way to configure these and deploy them to multiple machines? If so, how?
Vagrant does this but as virtual machines, which may be painfully slow.
What are some viable alternatives?
Absolutely, if you are talking about using a resource pool to deploy and configure your VMs (dev VMs).
For the sake of simplicity, I assume your virtual environment is hosted on VMWare.
Here are a few things to start off with
For Automating creation of VMs (deploying from templates, configure networking etc) you can use VMWare's PowerCLI (Powershell cmdlets) - more on this here
If your dev environment is purely Windows then, for configuration management, you can use DSC (free) or if you (your org) can afford go the expensive route of using SCCM
If you have a lot of Linux boxes to configure then, fortunately, you have more than one option - Ansible, Chef, Puppet or SaltStack
Spinning off and configuring these machines on demand entirely depends on your needs. One of the (more common ways) to do is, create a VM template (aka base vm) and then deploy a VM from this template.
This base template is usually a bare-bones OS + some common utils + tools - Once a VM is deployed from the template, you can then use one of the above mentioned CM (Configuration Management) tools to install/configure this VM.
Hope this gives some pointers in the right direction

how I can connect remotely to a machine and use the console, without knowing its IP address?

I need to remotely access to the linux console of some machine, but i dont have that IP (and looks like it will be a dinamyc ip)
I have my PC "A", and other PC "B". I have local access to both to install and configure whatever is required, but the PC "B" will be located elsewhere.
Is ssh the best way to go? how?
Thanks!
Since Yogipriyo offered a visual solution, here is how you can access SSH without the need of a GUI. Really, it depends on what you are comfortable with; I would personally recommend it.
There are plenty of ways to utilize SSH depending on your OS (that is, "computer A's OS"):
Windows: MobaXTerm, Cygwin, and Putty are the popular ones that I've heard about. I like MobaXTerm simply because you can have multiple tabs.
Mac: Most have the ability to SSH built in via the X11 terminal. You might need to install XQuartz to enable X11 port forwarding though if this isn't working for you.
*Nix: Just get to command line; you probably know that.
Once you are there, Vim is a great editor to know. This again is a "text-based" editor and thus lends itself well to use over SSH.
Keep in mind a lot of this is personal opinion, so explore and find what makes you most productive.
For visual solution, you can use Team Viewer.
It uses it's machine ID (which assigned by the team viewer application once you install it) to connect to the machine. I used it for 2 years at my previous job as remote support and it didn't have any trouble with dynamic IP as long as you have the target's team viewer ID.
For text based, as far as I know you need the target's IP or domain, but alas it still needs static IP.

Working on remote server

My OS: Windows 8
Virtualbox guest: Ubuntu 12.10 server
I configured apache server on vbox guest and mapped http, https, ssh port successfully into ubuntu server. It works nice without any problem.
I tried several IDEs like PHPStorm, Netbeans, editors like Sublime, all they do is to copy whole project from server, edit on local machine then sync back.
But it is not what I need. I want to work directly on guest server using ssh/sftp connection. I know that notepad++ has this functionality but I love sublime look and feel.
Is there any way to work on guest server with sublime or any other ide for free? (There is sftp solution but it's paid and works just like other ide's, not directly on guest machine) Any suggestions?
There are two approaches you can choose from, you will probably select the second one:
Use the KDE desktop environment (yes, it also exists for MS Windows). It features so called 'kio-slaves' which allow to use any protocol out there as if you were doing local file system operations. That means when using a KDE editor like 'kate' or even a whole IDE like 'kdevelop4' you can simply say "open file/project" and not only choose a local file, but something like sftp://server/path/file and start working. The network stuff is handled transparently by the environment, it is fully network transparent. This is how systems should be like. I think the GNOME environment had something similar, but it probably has been removed with version 3 of GNOME.
You can 'mount' the guests file system into your MS-Windows file system. not sure about the details how this works in MS-Windows, but I am sure that at least newer versions of MS-Windows have gained such feature. Most likely you are still limited to creating something like a "network harddrive" or something, in other systems (linux, unix, macOS) you can mount whereever in the file system you like. You can use any protocol for this, as long as it is supported by the mounting tools of your local system.
Again two options:
2.a You mount the whole virtual disk. Easy, but might be a problem if that disk is currently used by the guest system.
2.b You export the virtual disk by starting some server in the virtual system: samba is most likely your choice. Then you can mount that smb file export inside your MS-Windows system and start hacking.
Have fun!