2016-03-29 10 views
1

Ich habe ein Python-Skript, das einen Hashwert ausgibt. Ich möchte, dass dieser Hash in meine Variable innerhalb des ansible-Skripts geleitet wird.Piping einer Python-Ausgabe in eine Ansible-Variable

Der Python-Befehl sieht aus wie this-

#!/bin/python 
import crypt 
test= crypt.crypt('test', '[email protected]$') 
print test 

Mein ansible Textbuch wie folgt aussieht -

hosts: webservers 
    remote_user: test 
    become: yes 
    become_method: sudo 

    vars: 
     pass: 


    tasks: 

    - name: Run Python Password script 
    command: /home/test/userPW.py > pass 

Dank

+0

Siehe https://serverfault.com/questions/537060/how-to-see-stdout-of-ansible-commands. Siehe auch https://meta.stackoverflow.com/questions/294923/are-ansible-puppet-chef-salt-questions-on-topic – sashoalm

Antwort

4

bei registrieren Versuchen.

➜ ~ cat test.yml 
--- 
- hosts: 127.0.0.1 
    user: jenkins 
    connection: local 
    tasks: 
    - name: password 
     shell: cat /tmp/pass 
     register: pass 

    - debug: var=pass.stdout 

➜ ~ ansible-playbook -i hosts test.yml 


PLAY *************************************************************************** 

TASK [setup] ******************************************************************* 
ok: [127.0.0.1] 

TASK [password] **************************************************************** 
changed: [127.0.0.1] 

TASK [debug] ******************************************************************* 
ok: [127.0.0.1] => { 
    "pass.stdout": "mypassword" 
} 

PLAY RECAP ********************************************************************* 
127.0.0.1     : ok=3 changed=1 unreachable=0 failed=0