Deploying applications on a distant computer using a Python script

For my current project, I am attempting to remotely install an "environment" on a machine using a Python script. This particular environment requires the user name and password to be passed to it. Despite trying various approaches, I have not been successful in getting it to work as expected. The closest I have come is with this script, but even then, a GUI popup appears requesting the password after passing the user name. I'm puzzled about what I might be doing wrong or how I can modify the script to achieve the desired outcome. Below is a snippet of the script involving pexpect:


import os
import pexpect

cmd = 'ssh -X groupName@machineName cd ~/theLocationOfTheInstallation/ && pwd && theFullPathOfTheFileToInstall'
child = pexpect.spawn(cmd)
cmd_show_data = ''
usr = 'userName'
pas = 'myPassword'
while not child.eof():
    index = child.expect(['Please enter your.*','pass.*', pexpect.EOF, pexpect.TIMEOUT])
    cmd_show_data += child.before
    child.delaybeforesend = 1
    if index == 0:
        print 'user name required, "'+usr+'" is passed'
        child.sendline(usr)
    elif index == 1:
        print 'password required, "'+pas+'" is passed'
        child.sendline(pas)
    elif index == 2 :
        print 'EOF'
    elif index == 3:
        print 'TIMEOUT'
cmd_show_data += child.before
cmd_show_data  = cmd_show_data.split('\r\n')
for s in cmd_show_data:
    print s

There is a GUI prompt that appears, which you can view here: https://i.stack.imgur.com/w4gcW.png. If I manually enter the password (which I intend to avoid), the output looks something like this:

user name required, "userName" is passed
TIMEOUT
TIMEOUT (multiple occurrences)
user name required, "userName" is passed
TIMEOUT
TIMEOUT (multiple occurrences)
password required, "myPassword" is passed
TIMEOUT
TIMEOUT (multiple occurrences).... until the installation completes.

If anyone has any insights or suggestions, they would be greatly appreciated.

Answer №1

If you're determined to tackle this task using Python only, have you considered utilizing Ansible as an alternative?

Here's an Ansible solution:

If you possess a script that can install software locally, you can execute that same script on remote servers by utilizing the Ansible script module

# Example from Ansible Playbooks
- script: /some/local/script.py 1234

Example Python file :

#!/usr/bin/python

import sys

print 'Number of arguments:', len(sys.argv), 'arguments.'
print '1st Argument :', str(sys.argv[1])

For more information, check out these documentation links:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Steps for importing the mongo variable from the app that is bound to the application

I have two files, app.py and views.py app.py from flask import Flask from flask_pymongo import PyMongo app = Flask(__name__) app.config["MONGO_URI"] = "mongodb://local:27017/local" mongo = PyMongo(app) from views import profileview profileview.register(ap ...

Executing a program using Selenium to gather information

Current Progress I successfully developed a Python script that utilizes Selenium to open a Firefox browser and extract data to an excel file. Furthermore, I have converted this script into an executable file without encountering any errors thanks to Pyins ...

Having trouble running Selenium Chrome Driver on Pi Zero with error code -4?

Having trouble setting up a script on my new Pi Zero W after it was previously working on my Pi 3 B. It seems like the hardware may be the culprit as simply transferring the entire operating system to the new pi results in this issue, with no other changes ...

Having Trouble Accessing Website Using Python Script on Firefox

After attempting to launch a website in Firefox using Selenium Python, the browser opens but nothing happens beyond that. An error message was encountered during this process: bash-3.1$ C:/Users/user/AppData/Local/Programs/Python/Python35-32/python.exe d: ...

Is it possible to disregard text formatting in Python when using Selenium?

I am experiencing an issue when trying to compare a name from my name string to a name in a webelement. For instance: Name format in my namestring (scraped from a website): Mcburnie Name in webelement: McBurnie The Xpath matching fails because the webe ...

Export template function can be used to transfer a specific

I am looking to utilize a templated function called connect: template<class InstanceClass> CL_Slot connect (InstanceClass *instance, void(InstanceClass::*function)(Param1, Param2)) This function is used to connect a signal passed function from a sp ...

Employ splinter for updating the content of an HTML body

After examining the page source, I discovered that the forum content is contained within an unnamed iframe structured like this: <iframe style="height: 360px;"> <html> <body> Forum discussions are displayed here. ...

Is there a more efficient method for performing binary operations in Python that I can use to speed up calculations

Let's say I have a binary string: z = abc, where a, b, and c are either 0 or 1. We can convert c into an integer ranging from 0 to 7. Now, I want to assign another 'layer' of value to a, b, and c, where a = 1/2^1 = 1/2, b = 1/2^2 = 1/4, and ...

A guide on selecting a video with Selenium

I'm a newcomer to the world of coding with Python and its libraries, as well as being new to Stack Overflow. I apologize if I seem unfamiliar with some things. Now, onto my question. I am attempting to write a script that can automate playing a video ...

Ways to retrieve data from another tab using Selenium

From my understanding, Selenium currently opens a "private" browser tab. I am curious if there is a way to modify this behavior so that the Selenium tab can interact with other open tabs, allowing it to access logged-in sessions without needing to log in ...

Displaying Time in 24-hour format in Django Admin DateTimeField

I did some searching on Google, but I couldn't find a solution. On the Django admin side, I have the start date and end date displayed with time in 24 hr format. However, I would like to change it to display in 12 hr format instead. class CompanyEven ...

Searching for JSON data based on a specific key value filter using the jq query language

I am seeking assistance with filtering and extracting keys from a JSON file that contains key-value pairs. Specifically, I need to filter based on the inner key value pair within each key. Any guidance on how to accomplish this would be greatly appreciated ...

Wrapper for establishing database connections

Here is a class I have designed to simplify my life: import pymssql class DatabaseConnection: def __init__(self): self.connection = pymssql.connect(host='...', user='...', password='...', database='...' ...

When utilizing Beautiful Soup and Scrapy, I encountered an error indicating a reference issue prior to assignment

I encountered an issue while trying to scrape data which resulted in the error message UnboundLocalError: local variable 'd3' referenced before assignment . Can anyone provide a solution to resolve this error? I have searched extensively for a so ...

Get the month value from a DateField within a Django template

Are you looking to retrieve the month and year from a template file? template_1.html <form method='POST'> <input type='month' name='searchmonth'> <input type='submit' value='Sear ...

How to incorporate a personalized widget into a QTableWidget using PySide6

I've been attempting to incorporate my custom widgets into a QTableWidget, and while they are being added, they're not displaying correctly. The issue seems to be related to spacing within the cell boundary and the QWidget itself. Below is the sn ...

Make sure to wait for the stored procedure to finish executing before running the Python script in Node/Express using Tedious

I'm struggling to figure out how to properly time the execution of a python script following the completion of a SQL Server stored procedure via a router.post (express4/tedious): router.post('/post/create', textParser, function (req, res) { ...

How can I determine the specific quantity of XPATH links with unique identifiers in Selenium?

Seeking automation with Python3 and selenium to streamline searches on a public information site. The process involves entering a person's name, selecting the desired spelling (with or without accents), navigating through a list of lawsuits, and acces ...

Encountering a delay on the Ebay website following the login button click using Selenium in Python

While working on code to log in to a website, I have encountered an issue. The code successfully gets the webpage and accepts cookies, but when attempting to click the login button, the page hangs and the login page fails to load. from selenium import webd ...

update content of input field using Python Selenium

Hey, I have a snippet of code that looks like this: <input id="txt_search" class="search-box tp-co-1 tp-pa-rl-5 tp-re tp-bo-bo" type="text" placeholder="Search Stocks" onmouseup="this.select();" autoco ...