This commit is contained in:
Vadim Shulkin 2025-03-03 21:09:39 -05:00
commit 122741c989
5 changed files with 41 additions and 0 deletions

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
requests
pandas

19
run_python_script.yml Normal file
View File

@ -0,0 +1,19 @@
- name: Run Python Script with External Functions
hosts: localhost
gather_facts: no
tasks:
- name: Ensure required Python packages are installed
pip:
requirements: /Users/vadimshulkin/playbooks/requirements.txt # Ensure dependencies are installed
- name: Run the Python script
command: python3 /Users/vadimshulkin/playbooks/scripts/my_script.py
register: script_output
- name: Show script output
debug:
msg: "{{ script_output.stdout }}"

Binary file not shown.

17
scripts/my_script.py Normal file
View File

@ -0,0 +1,17 @@
import sys
from pathlib import Path
# Ensure the script can locate utils.py
sys.path.append(str(Path(__file__).parent))
# Import custom functions
from utils import greet_user
def main():
user = "Ansible AWX"
message = greet_user(user)
print(message)
if __name__ == "__main__":
main()

3
scripts/utils.py Normal file
View File

@ -0,0 +1,3 @@
def greet_user(name):
return f"Hello, {name}! Your Python script is running via Ansible AWX."