I have created several Python scripts, including a main.py
script that sequentially runs 4 other Python scripts.
I need to deploy and run them using Ansible. The issue is that I can’t use ansible.builtin.script
because only main.py
is used and not the others, so I’m using ansible.builtin.command
.
My problem is that I’m using a config file variables.json
, which I first populate with ansible.builtin.template
, and then it’s sent to the files
directory of my role, where the Python scripts are located. But every time, in the return code (rc) of my Python script, I get “undefined variables”. I think my scripts can’t “see” the config file.
Can you help me, please?
Thank you! 🙂
`---
- name: Generate the JSON configuration file
template:
src: variable.json.j2
dest: "{{ input_path }}/variable.json" # Generate the variable.json file in /tmp
- name: Copy all necessary files to the server
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ input_path }}//{{ item }}"
loop:
- main.py
- migration_zabbix_dezip_config_file.py
- migration_zabbix_hostname_recovery.py
- migration_zabbix_create_csv_file.py
delegate_to: localhost
- name: Run the main.py script
ansible.builtin.command:
cmd: python3 "{{ input_path }}//main.py"`
Nawel Laïdouni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.