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

---
name: Uptime Play
hosts: Test_Servers

*tasks:*
* - name: Get Server uptime first*
*     shell: uptime*
*     register: hello*
*   when: *ansible_system* is "Linux"*

*- debug: msg="{{ hello.stdout }}"*
*- debug: msg="{{ hello.stderr }}"*

* - name: Get System date and time*
*    shell: date*
*    register: hello*
*- debug: msg="{{ hello.stdout }}"*
*- debug: msg="{{ hello.stderr }}"*


On Fri, Sep 18, 2020 at 12:59 PM madan gopal <[email protected]>
wrote:

> Helo all,
>
> Can anyone help me with this playbook ? Any path to achieve my end goal
> also helps
>
> Regards,
> Madan
>
> On Thursday, September 17, 2020 at 3:47:29 PM UTC+5:30 madan gopal wrote:
>
>> 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,
>>
>> *---*
>> *- name: Get server uptime*
>> *   hosts: all*
>> *   vars_prompt:*
>> *    - name: "Server Name"*
>> *      prompt: "Enter VSphere Hostname or IP Address"*
>> *      private: no*
>>
>> *    - name: "Username"*
>> *      prompt: "Enter Server Login Username"*
>> *      private: no*
>>
>> *    - name: "Password"*
>> *      prompt: "Enter Server Login Password"*
>>
>> *   - name: "VMname"*
>> *     prompt: "Enter VM Hostname"*
>> *     private: no*
>>
>> *tasks:*
>> * - name: Get Server uptime first*
>> *   shell: uptime*
>> *   register: hello*
>> *- debug: msg="{{ hello.stdout }}"*
>> *- debug: msg="{{ hello.stderr }}"*
>>
>> * - name: Get System date and time*
>> *    shell: date*
>> *    register: hello*
>> *- debug: msg="{{ hello.stdout }}"*
>> *- debug: msg="{{ hello.stderr }}"*
>>
>> I tried different ways but, cannot call different OS versions in one
>> playbook.
>>
>> Any sort of assistance is greatly appreciated.
>>
>> Note: It should review the Operating System of the Server and accordingly
>> run "uptime" command to display the output.
>>
>> Regards,
>> Madan Gopal
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/879f4c54-b522-4c95-b458-37a16f30ee7fn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/879f4c54-b522-4c95-b458-37a16f30ee7fn%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAANJ-QRKvH-aQo9pS6BMDzBC%2BBEfpK4%2ByTTv97TD2KKiBCA2PA%40mail.gmail.com.

Reply via email to