In a Bash script we need to write $1 instead the variable, remove the read command, define the survey in the AAP to execute the Bash file, and add the arguments in the shell module. It works. Now, how is it for a Python script?
Trying to make a TXT file with the value that the user inputs works in local witout any problem:
print("Enter your value")
name = input()
with open("/us/gr_comun/prueba_py_ansible.txt", "w") as file:
file.write(f"{{name}}")
Following how it is for Bash, the Python script should look like this:
print("Enter your value")
with open("/us/gr_comun/prueba_py_ansible.txt", "w") as file:
file.write(f"{{$1}}")
It does not work.
The YML:
- name: RUN PYTHON ON TARGET
changed_when: false
shell: python3 /.../try_python.py {{side_a}}
become: true
become_user: xxxx
register: py_output
The script (adapted to AAP and tested locally):
# name = input()
with open("/.../try_txt.txt", "w") as file:
file.write(f"{{$1}}")
The survey contains only the side_a variable, and it is working already for Bash cases.
It runs the python script in a Remote Host.
Does anybody know how it would be?
I tried several variations, and look for an answer over the Internet. I expect to pass user input for python through AAP.