I have a python script inside ansible playbook:
---
- hosts: localhost
become: yes
become_method: sudo
become_user: root
gather_facts: false
tasks:
- name: execute script
command: ./qwe.py
register: python_output
- debug:
var: python_output.stdout_lines
qwe.py :
#!/usr/bin/python
import subprocess
import os
import json
import ssl
import platform
from requests import get
#import psutil
data = subprocess.Popen(['uname', '-r'], stdout = subprocess.PIPE)
output = str(data.communicate())
a = output[2:len(output)-10]
if "3.10.0-1062.9.1.el7.x86_64" == a:
print(json.dumps({"status":"pass", "kernelVersion":a}))
else:
print(json.dumps({"status":"fail", "kernelVersion":a}))
b = ssl.OPENSSL_VERSION
if "OpenSSL 1.0.2k-fips 26 Jan 2017" == b:
print(json.dumps({ "status":"pass","OpenSSLVersion":b}))
else:
print(json.dumps({"status":"fail", "OpenSSLVersion":b}))
I need to pass these list of values, for example :"OpenSSL 1.0.2k-fips 26 Jan 2017","3.10.0-1062.9.1.el7.x86_64" from outside the script instead of haedcoding it.In this way, i have 15 values I need to pass.
How can we achive it? Thanks for your help and time!!