Jenkins Ansible EC2动态库存不起作用

时间:2016-03-10 15:23:28

标签: jenkins amazon-ec2 ansible ansible-inventory

更新

不记得我是如何修复的,但似乎只是因为ec2.py脚本的权限错误。

我在动态广告资源设置的Ansible上部署了一些AWS EC2个剧本。

在服务器

中使用ansible-playbook时,它可以正常工作
ansible-playbook setup.yml

它位于Ubuntu 14.04Ansible 2.0.1.0,默认为/etc/ansible/ansible.cfg

[defaults]
remote_user = ubuntu
hostfile = /etc/ansible/ec2.py
host_key_checking = False

我得到了ec2.pyec2.ini http://docs.ansible.com/ansible/intro_dynamic_inventory.html

使用此插件https://wiki.jenkins-ci.org/display/JENKINS/Ansible+Plugin

Jenkins上触发播放手册时

它返回ec2.py的错误,因为它认为hostfile是ini file

ERROR! The file /etc/ansible/hosts is marked as executable, but failed to execute correctly. If this is not supposed to be an executable script, correct this with `chmod -x /etc/ansible/hosts`.
Inventory script (/etc/ansible/hosts) had an execution error: Traceback (most recent call last):
  File "/etc/ansible/hosts", line 1328, in <module>
    Ec2Inventory()
  File "/etc/ansible/hosts", line 177, in __init__
    self.do_api_calls_update_cache()
  File "/etc/ansible/hosts", line 424, in do_api_calls_update_cache
    self.get_instances_by_region(region)
  File "/etc/ansible/hosts", line 469, in get_instances_by_region
    conn = self.connect(region)
  File "/etc/ansible/hosts", line 440, in connect
    conn = self.connect_to_aws(ec2, region)
  File "/etc/ansible/hosts", line 458, in connect_to_aws
    conn = module.connect_to_region(region, **connect_args)
  File "/usr/local/lib/python2.7/dist-packages/boto/ec2/__init__.py", line 66, in connect_to_region
    return region.connect(**kw_params)
  File "/usr/local/lib/python2.7/dist-packages/boto/regioninfo.py", line 187, in connect
    return self.connection_cls(region=self, **kw_params)
  File "/usr/local/lib/python2.7/dist-packages/boto/ec2/connection.py", line 103, in __init__
    profile_name=profile_name)
  File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 1100, in __init__
    provider=provider)
  File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 569, in __init__
    host, config, self.provider, self._required_auth_capability())
  File "/usr/local/lib/python2.7/dist-packages/boto/auth.py", line 989, in get_auth_handler
    'Check your credentials' % (len(names), str(names)))
boto.exception.NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV4Handler'] Check your credentials

/etc/ansible/hosts:3: Error parsing host definition ''''': No closing quotation 

如果我将选项Inline contentDynamic inventory一起使用,那么它会使用这样的随机.ini文件

/usr/local/bin/ansible-playbook /data/ansible-playbooks/setup.yml -i /tmp/inventory487543089183487870.ini -f 5
 [WARNING]: provided hosts list is empty, only localhost is available

以前是否有人遇到此问题?

1 个答案:

答案 0 :(得分:0)

库存无法加载ENV。上述错误意味着无法加载凭据。我使用IAM凭证更新~/.aws/credentials,然后现在该剧本工作正常。