今天推出了GitLab.com更新,我发现使用Ansible连接到特定AWS区域的问题: us-gov-west-1 。
这很奇怪,因为在我的CI工作中,我能够正确使用AWS CLI:
CI构建步骤:
$ aws ec2 describe-instances
输出(截断):
{
"Reservations": [
{
"Instances": [
{
"Monitoring": {
"State": "disabled"
},
"PublicDnsName": "ec2-...
构建步骤如下,请注意它无法连接到该区域:
CI构建步骤:
$ ansible-playbook -vvv -i inventory/ec2.py -e ansible_ssh_private_key_file=aws-keypairs/gitlab_keypair.pem playbooks/deploy.yml
输出(截断)
Using /builds/me/my-project/ansible.cfg as config file
ERROR! Attempted to execute "inventory/ec2.py" as inventory script: Inventory script (inventory/ec2.py) had an execution error: region name: us-gov-west-1 likely not supported, or AWS is down. connection to region failed.
ERROR: Job failed: exit code 1
还有其他人看到这个吗?
今天上午工作了。知道为什么现在可能会失败吗?
答案 0 :(得分:0)
我写了一个小的Python脚本,深入了解boto。当我用Google搜索如何列出区域时,我被提醒了boto 2与boto 3之间的差异。然后,我回顾了我用来安装boto的机制。看起来好像是boto安装问题。
这是我的.gitlab-ci.yml
文件的错误版本:
image: ansible/ansible:ubuntu1604
test_aws:
stage: deploy
before_script:
- apt-get update
- apt-get -y install python
- apt-get -y install python-boto python-pip
- pip install awscli
script:
- 'aws ec2 describe-instances'
deploy_app:
stage: deploy
before_script:
- apt-get update
- apt-get -y install python
- apt-get -y install python-boto python-pip
- pip install awscli
script:
- 'chmod 400 aws-keypairs/gitlab_keypair.pem'
- 'ansible-playbook -vvv -i inventory/ec2.py -e ansible_ssh_private_key_file=aws-keypairs/gitlab_keypair.pem playbooks/deploy.yml'
这是固定版本:
image: ansible/ansible:ubuntu1604
all_in_one:
stage: deploy
before_script:
- rm -rf /var/lib/apt/lists/*
- apt-get update
- apt-get -y install python python-pip
- pip install boto==2.48.0
- pip install awscli
- pip install ansible==2.2.2.0
script:
- 'chmod 400 aws-keypairs/gitlab_keypair.pem'
- 'aws ec2 describe-instances'
- 'python ./boto_debug.py'
- 'ansible-playbook -vvv -i inventory/ec2.py -e ansible_ssh_private_key_file=aws-keypairs/gitlab_keypair.pem playbooks/deploy.yml'
请注意,我已从使用apt-get install
切换为使用pip install
。希望其他人将来会遇到这篇文章,并避免使用apt-get -y install python-boto
安装boto!