Easy question.
I have a Python3 script on my remote node in the path ~/setup/inventory.py, and I am trying to execute it remotly.
So I took a look at the script resource, which is searching on my local machine for the script.
How do I get Ansible to run my remote Python3 script. Executing it normally would look like os python3 /setup/inventory.py ansible vscode bash
Use command or shell modules, depending on your case.
Something like
- name: execute my script
command: python3 /setup/inventory.py ansible vscode bash
Related
I use NiFi on Windows 10 machine with installed Linux subsystem (Ubuntu).
My task is to execute bash scripts and commands using NiFi. I tried to use ExecuteProcess and ExecuteStreamCommand with selected commands like simply 'bash' or 'bash ls' for test purposes, but all I got was:
ExecuteProcess[id=4f530725-0171-1000-d1b1-7df587eada7e] /bin/ls:
/bin/ls: cannot execute binary file
If I try to pass basic Windows commands everything is OK.
Is there a way to run bash commands in my case?
I'm not a Windows user but according to the docs, in order to get to the Linux-style commands you have to run Bash.exe, so I'm guessing you'll need to specify -c as an argument followed by the Linux bash command you want to run (as a string), something like:
bash -c "ls"
I am trying to setup a playbook which will execute the env file of a service before running the command to stop the service.
Note that stop or start service command will only work after execute that env file.
The command to execute the env file is . ./.env_file_name or ksh .env_file_name
I am not able to execute the file using the above command in command module and shell module.
How to execute the above env file in ansible ?
How to run the stop command after executing the env file ?
If env file contains some environment variables that you need to set before running stop, then you can read the file, store results in a variable, then use environment keyword to provide them to the task, that actually stops the service.
Alternatively, you can add multiple commands in shell module at once, like so:
- name: Example for a shell module
shell:
cmd: |
./.env_file_name
./stop.sh (insert command to stop the service here)
I am trying to run a command after setting up an environment. This command runs a python script which depends on the environment.
I have the following code:
#!/bin/bash
source ~/some/linux/env/shell
python test.py
However, the "python test.py" only runs after I exit the env shell.
I want to be able to run the "python test.py" inside this new shell env.
Firstly adding python running and interpreting directory.
#!/usr/bin/env python
And you have to give a code execution authority. You can give a permission below
chmod a+x test.py
Now you can run it from the command line.
./test.py
I develop my own django-based project with pipenv.
Couple days ago I created simple bash script to speed up boring stuff.
All time I run terminal, go to the same directory and execute pipenv shell, after that I open up project in VScode code . and started python manage.py runserver for looking up my progress.
I try create script which do the same stuff but simplied, just run webber and here go (it comes from /usr/local/bin).
But I have one problem of these, I can't keep my pipenv shell running and execute python manage.py runserver at the same time. I mean when I stop Ctrl+C python server I don't receive my virtual enviroment (this happed in bash script ~ normally work fine).
However, server is start up, so it's virtual env.
I tried with pipenv run command but it doesn't get inside virtual env at all.
Script:
#!/bin/bash
cd ~/Documents/myprojects/Webber
code .
source $(pipenv --venv)/bin/activate
python manage.py runserver
My question is: How can I run command inside virtualenv in shell script and receive this subshell?
you can use the full path to the virtualenv folder instead of pipenv command. For example, if you created the virtual environment in you home directory called venv-webber:
source $HOME/venv-webber/bin/activate
Inside my ruby script I need to run a script sh which is located in another machine (opening an ssh connection?) and then continues with my program.
So:
my ruby script (e.g: Machine 10.1.1.2)
generic command
generic command
...
RUN SCRIPT UPDATE.SH ON MACHINE 10.1.1.15
generic command
generic command