From 5b6984eb0f97a974e77e499952c7e0197427c2ed Mon Sep 17 00:00:00 2001 From: Michele Baldessari Date: Wed, 20 Mar 2019 12:34:58 +0100 Subject: [PATCH] Fixup ipaclient.yaml for python3 This change does two things: 1. it uses print() which is the only supported way of calling print in python3 (and still works with python2). This way we avoid the following error: SyntaxError: Missing parentheses in call to 'print'. Did you mean print('...')? 2. It uses the PythonInterpreter variable to choose the python interpreter Tested and we correctly get the right wanted interpreter: ... fqdn=`echo $data | /usr/bin/python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("join", {}).get("hostname", ""))'` ... Change-Id: I6e68664c650d0481a9f0cfd21985434d8c75e1a2 Co-Authored-By: Luca Miccini --- extraconfig/services/ipaclient.yaml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/extraconfig/services/ipaclient.yaml b/extraconfig/services/ipaclient.yaml index 1553c36a33..7014af3aef 100644 --- a/extraconfig/services/ipaclient.yaml +++ b/extraconfig/services/ipaclient.yaml @@ -32,6 +32,10 @@ parameters: description: Mapping of service endpoint -> protocol. Typically set via parameter_defaults in the resource registry. type: json + PythonInterpreter: + type: string + description: The python interpreter to use for python and ansible actions + default: /usr/bin/python outputs: role_data: @@ -43,6 +47,8 @@ outputs: host_prep_tasks: - name: enroll client in ipa and get metadata become: yes + vars: + python_interpreter: {get_param: PythonInterpreter} block: - name: install needed packages package: @@ -67,7 +73,7 @@ outputs: if [ -f /run/cloud-init/status.json ]; then # Get metadata from config drive data=`cat /run/cloud-init/status.json` - config_drive=`echo $data | python -c 'import json,re,sys;obj=json.load(sys.stdin);ds=obj.get("v1", {}).get("datasource"); print re.findall(r"source=(.*)]", ds)[0]'` + config_drive=`echo $data | {{ python_interpreter }} -c 'import json,re,sys;obj=json.load(sys.stdin);ds=obj.get("v1", {}).get("datasource"); print(re.findall(r"source=(.*)]", ds)[0])'` if [[ -b $config_drive ]]; then temp_dir=`mktemp -d` mount $config_drive $temp_dir @@ -109,15 +115,15 @@ outputs: fi # Get the instance hostname out of the metadata - fqdn=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print obj.get("join", {}).get("hostname", "")'` + fqdn=`echo $data | {{ python_interpreter }} -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("join", {}).get("hostname", ""))'` if [ -z "$fqdn" ]; then echo "Unable to determine hostname" exit 1 fi - realm=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print obj.get("join", {}).get("krb_realm", "")'` - otp=`echo $data | python -c 'import json,sys;obj=json.load(sys.stdin);print obj.get("join", {}).get("ipaotp", "")'` + realm=`echo $data | {{ python_interpreter }} -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("join", {}).get("krb_realm", ""))'` + otp=`echo $data | {{ python_interpreter }} -c 'import json,sys;obj=json.load(sys.stdin);print(obj.get("join", {}).get("ipaotp", ""))'` hostname=`/bin/hostname -f`