我有一个输出哈希的python脚本。我希望将该哈希管道传输到ansible脚本中的变量中。
Python命令看起来像这样 -
#!/bin/python
import crypt
test= crypt.crypt('test', '$6$Som3S@lt$')
print test
我的ansible剧本看起来像这样 -
hosts: webservers
remote_user: test
become: yes
become_method: sudo
vars:
pass:
tasks:
- name: Run Python Password script
command: /home/test/userPW.py > pass
由于
答案 0 :(得分:4)
尝试注册。
➜ ~ 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