38 lines
1.1 KiB
YAML
38 lines
1.1 KiB
YAML
- name: Run Python Script with External Functions
|
|
hosts: localhost
|
|
gather_facts: no
|
|
tasks:
|
|
- name: Copy requirements.txt to remote host
|
|
copy:
|
|
src: ./requirements.txt # Ensure this exists locally
|
|
dest: /tmp/requirements.txt
|
|
|
|
- name: Create Python Virtual Environment
|
|
command: python3 -m venv /tmp/ansible_venv
|
|
args:
|
|
creates: /tmp/ansible_venv/bin/activate
|
|
|
|
- name: Install required Python packages
|
|
pip:
|
|
requirements: /tmp/requirements.txt
|
|
virtualenv: /tmp/ansible_venv
|
|
virtualenv_command: "python3 -m venv"
|
|
|
|
# - name: Check installed Python packages
|
|
# command: bash -c "source /tmp/ansible_venv/bin/activate && pip list"
|
|
# register: installed_packages
|
|
|
|
# - name: Show installed packages
|
|
# debug:
|
|
# msg: "{{ installed_packages.stdout }}"
|
|
|
|
- name: Run the Python script
|
|
command: /tmp/ansible_venv/bin/python3 scripts/my_script.py
|
|
register: script_output
|
|
|
|
- name: Show script output
|
|
debug:
|
|
msg: "{{ script_output.stdout.split('\n') }}"
|
|
|
|
|