Ansible World

Hello All,

I am completely new to Ansible and wanted to start my first baby steps with simple playbook which will help me out in my day-to-day works

Problem Statement: To verify remote server uptime both Windows and Linux
Solution: Prompt for ServerName and display uptime of the server

Linux : uptime
Windows: systeminfo | find “System Boot Time:”

This is my playbook which is not working,

Helo all,

Can anyone help me with this playbook ? Any path to achieve my end goal also helps

Regards,
Madan

I am assuming you are using all of the defaults. So what does your host file look like? I normally use ansible on the networking side - so it is little different then servers so take everything i am about to say with a grain of salt. I don’t have a server to test these commands against - this is just how I would start to approach it.

I would think that you would want use gather facts to find out what server type you are hitting or assign the variable in your host file. Your vars prompt is not needed, you should have that information in your host file. When you run your playbook it will use the username that you are logged in as on the control node. If you want to change that you would use the -u in the command when you execut the playbook. Also the password you would use a -k in the command.

Also it looks like the shell command module will not work with windows. ( https://docs.ansible.com/ansible/latest/modules/shell_module.html ) — It looks like there is a winshell module too though https://docs.ansible.com/ansible/latest/modules/win_shell_module.html#win-shell-module

So you will need to add a when statement in your tasks to only execute when it is a linux or windows server and create a new task for windows.

You should check out https://docs.ansible.com/ansible/latest/modules/modules_by_category.html to see what all of the modules do. Ansible has pretty good documentation. Hope this helps and doesn’t muddy the waters too much.

so the host file would be something like this

[Test_Servers]
server1.foo.com
server2.foo.com
server3.foo.com

your playbook would be something like that

Hello all,

Thank you very much for your inputs. I have modified my playbook as below