Ansible Automation: Gather list of all services on windows servers and clients

I had another audit request to gather all services on windows servers in an environment of about 70+ servers. I knew doing this through Ansible would be allot faster than going to each server individually. In the end it took less than 5 minutes to gather the services on 70+ servers.

When running the script I usually tee the output to text:

IE: ansible-playbook Audit_win_list_all_services.yml | tee /tmp/audit/Windows_services.txt

Here is my playbook:

Audit_win_list_all_services.yml

Ansible Automation: Gather list of all software installed on windows servers and clients

I had a request to gather all software installed on windows servers in an environment of about 70+ servers. I knew doing this through Ansible would be allot faster than going to each server individually. In the end it took less than 5 minutes to gather the installed software on 70+ servers.

I had seen a few playbooks online from other Ansible Admins doing this via Win32_Product, but I have seen warnings about using Win_32Product causing problems.

So after reading this article, I created the following playbook (I initially used a normal debug statement, but the output had allot of unnecessary info, so I split the output by newline and printed that list):

Below is my playbook:

win_list_all_programs.yml

Automating with Ansible: Adding new windows server clients to Prometheus/Grafana

I needed a way to install the Windows_Exporter on our Window systems as well as automating the configuration of the client in Prometheus. I came up with this Ansible playbook to handle this task. I’m sure there may be other ways of doing this and I’m always open to any suggestions. Here is what I have:

Playbooks (Can be downloaded):

win_install_prometheus.yml which calls install_prometheus_part2.yml

I imported a dashboard from Grafana.com, but at the time it only exported the older wmi_exporter. I was able to edit the dashboard and update it to work with the new exporter. Here is my dashboard (in JSON format for importing):

ESXI: How to power on-off vms via cli

To power on a virtual machine from the command line:
List the inventory ID of the virtual machine with the command:

vim-cmd vmsvc/getallvms |grep <vm name>

Note: The first column of the output shows the vmid.

Check the power state of the virtual machine with the command:

vim-cmd vmsvc/power.getstate <vmid>

Power-on the virtual machine with the command:

vim-cmd vmsvc/power.on <vmid>

Move KVM VM vm to HyperV

Found the following online on Novell’s site and it worked perfectly (link below)

Copy the disk to a pc with virtualbox installed the convert with:

c:\Program Files\Oracle\VirtualBox>VBoxManage convertfromraw c:\be\disk0-test.ra

w test.vhd –format VHD

Then copy the vhd to hyperv and do it

1. Boot the target machine into rescue mode, using appropriate boot media

2. Run the following command to determine which devices are /, /boot and swap:

fdisk -l

3. Using that information mount the appropriate devices:

mount /dev/%root device% /mnt

mount /dev/%boot device% /mnt/boot

mount –rbind /proc /mnt/proc

mount –rbind /sys /mnt/sys

mount –rbind /dev /mnt/dev

4. Change the system root to the newly selected location:

chroot /mnt

5. Modify the /etc/fstab file to make sure the correct devices are being used.  For example the root, boot, and swap devices might be listed with these device names:

/dev/sda1

/dev/sda2

/dev/sda3

According to the fdisk -l output, however, the devices should be listed as follows:

/dev/cciss/c0d0p1

/dev/cciss/c0d0p2

/dev/cciss/c0d0p3

6. Modify the /boot/grub/menu.lst file and replace the boot partition information with the correct device id.  For example, the boot partition may be listed as this device:

/dev/sda2

Where it should be this device:

/dev/cciss/c0d0p2

7. Make sure that the /var/tmp directory exists and then run the following command (note: the /var/tmp directory may need to be manually created first):

mkinitrd

8. Reboot the target machine

From <https://www.novell.com/support/kb/doc.php?id=7009643>

Linux: Output your microphone to other computer’s speaker & vise-versa over SSH

$ dd if=/dev/dsp | ssh username@host dd of=/dev/dsp

The default sound device on Linux is /dev/dsp. It can be both written to and read from. If it’s read from then the audio subsystem will read the data from the microphone. If it’s written to, it will send audio to your speaker.

This one-liner reads audio from your microphone via the dd if=/dev/dsp command (if stands for input file) and pipes it as standard input to ssh. Ssh, in turn, opens a connection to a computer at host and runs the dd of=/dev/dsp (of stands for output file) on it. Dd of=/dev/dsp receives the standard input that ssh received from dd if=/dev/dsp. The result is that your microphone gets output on host computer’s speaker.

Want to scare your colleague? Dump /dev/urandom to his speaker by dd if=/dev/urandom.

It works the other way as well:
ssh -C user@ipaddress arecord -f dat -D plughw:1,0|aplay -f dat