Hi Team, is it possible to package ansible-runner ...
# general
f
Hi Team, is it possible to package ansible-runner and ansible playbooks using PEX
h
I don't see why it wouldn't be possible. In principle if you can put it in a virtualenv you can put it in a pex. But I'm curious if anyone has done this in practice yet?
p
Be careful as ansible cannot be made into a wheel due to its use of symlinks in the code. You may hit a few speed bumps from those symlinks.
f
Hi Benjyw, FYI: we were able to build the executable successfully yesterday, Thanks a lot for quick response and help
today we will testing to by porting it other nodes
🤞 1
Appreciate your help!
It is failing when we using call ansible_runner using the relative path from package ex:
Copy code
r = ansible_runner.run(private_data_dir='./ansible_runner', playbook=playbook_name, quiet=False,
                       cmdline=cmd_line, rotate_artifacts=1)
./dist/src.python.sre_playbooks/sre_play.pex Config file loded validating auth token.... Remediation starting for localhost fsused-percent : disk_space_runbook.yml Check curret path: /Users/test/projects/test/pexPackage 2/hosts disk_space_runbook.yml ERROR! the playbook: disk_space_runbook.yml could not be found
we have checked the disk_space_runbook.yml is bundled inside ansible_runner/projects/disk_space_runbook.yml and file exists
a
@happy-kitchen-89482 @proud-dentist-22844 I have one more question, while using ansible_runner can we use Python’s 
open()
to read a 
resources
 target? Or “open()” is only available with
files
 target?
h
You should use resources. Files are not included in the PEX Alternatively you can use archive. https://www.pantsbuild.org/docs/resources
f
Hi @hundreds-father-404, We are trying package complete project with ansible-runner in single executable file but we are find issue running the playbooks as mentioned above(ERROR! the playbook: disk_space_runbook.yml could not be found). we have tried to testing https://github.com/alex-leonhardt/ansible-pex it also failed to build executable. could you please advise how to bundle ansible-runner with all other python scripts in single pex
h
How are you expressing the target that wraps the .yml file? It should probably be a
resources()
target.
And have you tried creating the pex with
execution_mode='unzip'
(or
'venv'
) ?