Ansible的库密钥的TypeError - Python

时间:2015-06-01 20:34:20

标签: python

我有以下Python代码:

from ansible.playbook import PlayBook                                                                                                                
from ansible.inventory import Inventory                                                                                                              
from ansible.inventory import Group                                                                                                                  
from ansible.inventory import Host                                                                                                                   
from ansible import constants as C                                                                                                                   
from ansible import callbacks                                                                                                                        
from ansible import utils                                                                                                                            

import os                                                                                                                                            
import logging                                                                                                                                       
import config 

def run_playbook(ipaddress, namenode_ip, playbook, keyfile):                                                                                                                                                                     
      utils.VERBOSITY = 0                                                                                                                              
      playbook_cb = callbacks.PlaybookCallbacks(verbose=utils.VERBOSITY)                                                                               
      stats = callbacks.AggregateStats()                                                                                                               
      runner_cb = callbacks.PlaybookRunnerCallbacks(stats, verbose=utils.VERBOSITY)                                                                    

      host = Host(name=ipaddress)                                                                                                                      
      group = Group(name="new-nodes")                                                                                                                  
      group.add_host(host)                                                                                                                             
      inventory = Inventory(host_list=[], vault_password="Hello123")                                                                              
      inventory.add_group(group)                                                                                                                       
      key_file = keyfile                                                                  
      playbook_path = os.path.join(config.ANSIBLE_PLAYBOOKS, playbook)                                                                                 
      pb = PlayBook(                                                                                                                                   
              playbook=playbook_path,                                                                                                                  
              inventory = inventory,                                                                                                                   
              remote_user='deploy',                                                                                                                    
              callbacks=playbook_cb,                                                                                                                   
              runner_callbacks=runner_cb,                                                                                                              
              stats=stats,                                                                                                                             
              private_key_file=key_file                                                                                                                
      )                                                                                                                                                

      results = pb.run()                                                                                                                               
      print results

我希望使用Ansible的API来执行剧本。但是,当我执行该脚本时:

python auto.py

我明白了:

Traceback (most recent call last):
  File "auto.py", line 66, in <module>
    run_playbook("1.1.1.1", "2.2.2.2")
  File "auto.py", line 62, in run_playbook
    results = pb.run()
  File "/usr/local/lib/python2.7/dist-packages/ansible/playbook/__init__.py", line 310, in run
    play = Play(self, play_ds, play_basedir, vault_password=self.vault_password)
  File "/usr/local/lib/python2.7/dist-packages/ansible/playbook/play.py", line 98, in __init__
    processed_vars_files = self._update_vars_files_for_host(None)
  File "/usr/local/lib/python2.7/dist-packages/ansible/playbook/play.py", line 938, in _update_vars_files_for_host
    if process_files(filename, filename2, filename3, filename4, host=host):
  File "/usr/local/lib/python2.7/dist-packages/ansible/playbook/play.py", line 880, in process_files
    data = utils.parse_yaml_from_file(filename4, vault_password=self.vault_password)
  File "/usr/local/lib/python2.7/dist-packages/ansible/utils/__init__.py", line 774, in parse_yaml_from_file
    data = vault.decrypt(data)
  File "/usr/local/lib/python2.7/dist-packages/ansible/utils/vault.py", line 136, in decrypt
    data = this_cipher.decrypt(data, self.password)
  File "/usr/local/lib/python2.7/dist-packages/ansible/utils/vault.py", line 555, in decrypt
    key1, key2, iv = self.gen_key_initctr(password, salt)
  File "/usr/local/lib/python2.7/dist-packages/ansible/utils/vault.py", line 505, in gen_key_initctr
    count=10000, prf=pbkdf2_prf)
  File "/usr/local/lib/python2.7/dist-packages/Crypto/Protocol/KDF.py", line 110, in PBKDF2
    password = tobytes(password)
  File "/usr/local/lib/python2.7/dist-packages/Crypto/Util/py3compat.py", line 85, in tobytes
    return ''.join(s)
TypeError

我确定keyfile有效且存在....任何线索?

**** keyfile="/home/ubuntu/.ssh/my_rsa_key"

0 个答案:

没有答案