https://pantsbuild.org/ logo
#general
Title
# general
g

gentle-sugar-52379

10/03/2022, 7:10 AM
im pretty sure im running in the wrong direction, again :) i try to automate a deployment with ansible-runner. so i wrote an
deployments/project_name/main.py
script and made it invokable with
python_source
. i'm able to run it with
./pants run deployments/project_name
with and without the sandboxing feature. pretty nice but ansible-runner wants to call
ansible-playbook
via subprocess. i tried to include it as a requirement in my
python_source
but without any luck. the next try was: make a fake
ansible-playbook
executable inside my
~/.local/bin folder
. result: my
deployments/project_name/main.py
is able to find and execute it. is it the right solution to globally install ansible so it's findable by my
deployments/project_name/main.py
script or is there something i could do to include it into the path to be able to rely on the automatic fetching of ansible?
e

enough-analyst-54434

10/03/2022, 7:15 AM
If you used a
pex_binary
target to run this with
exexution_mode="venv"
(https://www.pantsbuild.org/docs/reference-pex_binary#codeexecution_modecode) that should work. The venv execution mode puts all dependency console scripts on the
PATH
.
g

gentle-sugar-52379

10/03/2022, 7:19 AM
i tried that too, but maybe i made a mistake. i will try that again 🙂
e

enough-analyst-54434

10/03/2022, 7:21 AM
Well, try
./pants package
against the
pex_binary
venv mode target and then run the PEX file that creates as a second step. The
run
goal has changed a bit recently and I don't have a good grasp of what it does in which version of Pants currently.
This will help vet venv mode works 1st, then that just leaves figuring out which version of Pants has the right run goal semantics. @bitter-ability-32190 is expert on that.
g

gentle-sugar-52379

10/03/2022, 7:26 AM
oh, i think i figured it out: if i do not give the pex_binary a name it seems the python_source wins the
run
goal. if i give it a name the pex_binary gets executed. cool, thx a lot 🙂
b

bitter-ability-32190

10/03/2022, 1:06 PM
What version of pants are you on? Things have changed to make the end result consistent
g

gentle-sugar-52379

10/04/2022, 4:11 AM
2.14.0rc1
b

bitter-ability-32190

10/04/2022, 12:29 PM
Ok I reread the question. So first, by running using the directory name, it's actually a shorthand for the address path/to/dirname:dirname. Likewise if you omit the name= off a target, it defaults to the directory name. I recommend either running the file
main.py
or running the binary target by name.
2 Views