79777949

Date: 2025-09-29 09:26:29
Score: 1
Natty:
Report link

First, take note that according documentation Job Templation - Extra Variables

When you pass survey variables, they are passed as extra variables (extra_vars) ...

Then, the question becomes "How to use Ansible extra variables with Python scripts?" and minimmal examples could look like Run Python script with arguments in Ansible.

---
- hosts: localhost
  become: false
  gather_facts: false

  vars:

    survey_input: test

  tasks:

  - name: Create example Python script
    copy:
      dest: survey.py
      content: |
        #!/usr/bin/python

        import sys

        print("arguments:", len(sys.argv))
        print("first argument:", str(sys.argv[1]))

  - name: Run example Python script
    script: survey.py {{ survey_input }}
    register: results

  - name: Show result
    debug:
      msg: "{{ results.stdout }}"

It will result into an output of

TASK [Show result] *****
ok: [localhost] =>
  msg: |-
    arguments: 2
    first argument: test

Further Q&A

Which might be interesting and help in this Use Case

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Looks like a comment (1):
  • High reputation (-2):
Posted by: U880D