To transfer a script into remote hosts and run that script into the remote machines which needs some inputs to configure

341 views
Skip to first unread message

M I Chowdhury

unread,
Nov 19, 2017, 7:22:14 PM11/19/17
to Ansible Project
Dear Ansible friends,


I need some automation like to run a script into all remotes machines which requires some interactive input described as below:

Master server:
----------------------
/Having patch script here
/Need to Transfer the script to remote machines
/Execute the script into remotes machines which needs configuration inputs based on  on which host it is configuring.

Remote hosts:
-----------------------
/copied  the script here
/will run the script here which had some configuration inputs as below
1. Like what is the host name that you running the script?[hostX]:<get the host name and input host name here>
2. what is host database server name?<need to find out in a file which has a parameter db-host=hostdb> < input the host db here
3.
4...so on

How can I do this thing and handle properly? Kindly advise.

Thanks
M I Chowdhury 




Kai Stian Olstad

unread,
Nov 22, 2017, 9:49:26 AM11/22/17
to ansible...@googlegroups.com
On Monday, 20 November 2017 01.22.14 CET M I Chowdhury wrote:
> I need some automation like to run a script into all remotes machines which
> requires some interactive input described as below:
>
> Master server:
> ----------------------
> /Having patch script here
> /Need to Transfer the script to remote machines

The copy module can do that.


> /Execute the script into remotes machines which needs configuration inputs
> based on on which host it is configuring.

This can the expect module do.


> Remote hosts:
> -----------------------
> /copied the script here
> /will run the script here which had some configuration inputs as below
> 1. Like what is the host name that you running the script?[hostX]:<get the
> host name and input host name here>

In Ansible facts you have this information, and can use this in the expect module.


> 2. what is host database server name?<need to find out in a file which has
> a parameter db-host=hostdb> < input the host db here

To get this information, you can run the command module an register the output in a variable and then use that in the expect module.


--
Kai Stian Olstad

Iqbal Chowdhury

unread,
Nov 22, 2017, 6:03:47 PM11/22/17
to ansible...@googlegroups.com
Hi Kai,

Thanks for the reply.

Would you please provide some example based on my requirements?

And the other thing would like to know :
I have the Ansible installed in management node. And the other nodes which I am taking as remote hosts where the product software running are also having Ansible which product requires.
My question is :is that ok having Ansible installed in all remote hosts as well as management node?
Does it require same version of Ansible installed in all?

Thanks again
M I
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1817691.OA4ky2jAZB%40x1.
> For more options, visit https://groups.google.com/d/optout.

Kai Stian Olstad

unread,
Nov 23, 2017, 3:28:55 PM11/23/17
to ansible...@googlegroups.com
On Thursday, 23 November 2017 00.03.25 CET Iqbal Chowdhury wrote:
> Hi Kai,
>
> Thanks for the reply.
>
> Would you please provide some example based on my requirements?

This is very basic Ansible that you can learn from a book or read the Ansible docs[1].


> And the other thing would like to know :
> I have the Ansible installed in management node. And the other nodes which I am taking as remote hosts where the product software running are also having Ansible which product requires.
> My question is :is that ok having Ansible installed in all remote hosts as well as management node?

That's not a problem, Ansible is just a program waiting to be executed by the user.

> Does it require same version of Ansible installed in all?

Ansible doesn't require Ansible on the remote hosts, Ansible is agent-less and only requires SSH and Python on the remote hosts.
That said, some modules require additional Python modules on the remote node, this is documented in the documentation for each module.
And it's possible to use Ansible on entities that do not have Python.


[1] https://docs.ansible.com/


--
Kai Stian Olstad

Iqbal Chowdhury

unread,
Nov 26, 2017, 12:50:10 AM11/26/17
to ansible...@googlegroups.com
Thanks Kai for your feedback.

Now I am getting the below error:

[root@host- ansible]#
[root@host- ansible]#

[root@host- ansible]# ansible all -m ping -u root
SSH password:
SUDO password[defaults to SSH password]:
 [WARNING]:  * Failed to parse /etc/ansible/hosts with yaml plugin: Syntax Error while loading YAML.   The error appears to have been in '/etc/ansible/hosts':
line 3, column 1, but may be elsewhere in the file depending on the exact syntax problem.  The offending line appears to be:  #nfvd42ffgui 10.75.46.104 ^ here
exception type: <class 'yaml.parser.ParserError'> exception: did not find expected <document start>   in "<unicode string>", line 3, column 1

 [WARNING]:  * Failed to parse /etc/ansible/hosts with constructed plugin: Unable to parse /etc/ansible/hosts: Syntax Error while loading YAML.   The error
appears to have been in '/etc/ansible/hosts': line 3, column 1, but may be elsewhere in the file depending on the exact syntax problem.  The offending line
appears to be:  #nfvd42ffgui 10.75.46.104 ^ here  exception type: <class 'yaml.parser.ParserError'> exception: did not find expected <document start>   in
"<unicode string>", line 3, column 1

 [WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: Could not match supplied host pattern, ignoring: all

 [WARNING]: provided hosts list is empty, only localhost is available

 [WARNING]: No hosts matched, nothing to do

I  configure my /etc/ansible/hosts as below:

[FF12]
10.14.X.X
10.14.XX

and the ansible.cfg is set out with the default values.


Please suggest.

Thank you
M I C




Regards,
Iqbal Chowdhury




--
Kai Stian Olstad

--
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 ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5535008.pkajJAlBLd%40x1.

Kai Stian Olstad

unread,
Nov 27, 2017, 9:06:22 AM11/27/17
to ansible...@googlegroups.com
On Sunday, 26 November 2017 06.49.56 CET Iqbal Chowdhury wrote:
>
> Thanks Kai for your feedback.
>
> Now I am getting the below error:
>
> [root@host- ansible]#
> [root@host- ansible]#
>
>
> [root@host- ansible]# ansible all -m ping -u root
> SSH password:
> SUDO password[defaults to SSH password]:
> [WARNING]: * Failed to parse /etc/ansible/hosts with yaml plugin: Syntax
> Error while loading YAML. The error appears to have been in
> '/etc/ansible/hosts':
> line 3, column 1, but may be elsewhere in the file depending on the exact
> syntax problem. The offending line appears to be: #nfvd42ffgui
> 10.75.46.104 ^ here
> exception type: <class 'yaml.parser.ParserError'> exception: did not find
> expected <document start> in "<unicode string>", line 3, column 1
>
>
>
> I configure my /etc/ansible/hosts as below:
>
>
> [FF12]
> 10.14.X.X
> 10.14.XX
>
>
> and the ansible.cfg is set out with the default values.

Your error messages say your hosts file contains more info than that.
You get this error when inventory file called hosts in your case is wrong.
So if you don't share the whole file unedited we are not able to help.


--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages