2016-03-29 17 views
1

Karma bir çıktı veren bir python betiğim var. Bu karmaşanın içinde değişkenimin içine pipetlenmesini istiyorum.Bir python çıktısını Ansible değişkeni içine aktarma

Python komut böyle My yanıtlayıcı 'oyun kitabı görünüyor bu-

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

benziyor -

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

    vars: 
     pass: 


    tasks: 

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

Teşekkür

+0

https://serverfault.com/questions/537060/how-to-see-stdout-of-ansible-commands bakın. Ayrıca bkz. Https://meta.stackoverflow.com/questions/294923/are-ansible-puppet-chef-salt-questions-on-topic – sashoalm

cevap

4

sicil ile deneyin.

➜ ~ 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 
İlgili konular