2016-12-29 76 views
0

我从Travis-CI运行Ansible 2.2.0.0,以便安装我们在项目中使用的Terraform的共享版本。参数必须是str字节

我可以毫不问题在本地运行,但是当我在特拉维斯运行它,它似乎无法从一个变量源字符串的一些编码:

[WARNING]: Host file not found: /etc/ansible/hosts 

[WARNING]: provided hosts list is empty, only localhost is available 

PLAY [localhost] *************************************************************** 

TASK [setup] ******************************************************************* 
ok: [localhost] 

TASK [terraform : create terraform directory] ********************************** 
changed: [localhost] 

TASK [terraform : install terraform] ******************************************* 
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "msg": "Failure downloading https://releases.hashicorp.com/terraform/0.7.13/terraform_0.7.13_linux_amd64.zip, write() argument must be str, not bytes"} 

PLAY RECAP ********************************************************************* 
localhost     : ok=2 changed=1 unreachable=0 failed=1 

主机Ansible和Python版本:

[email protected]:/vagrant/ansible$ python3 --version 
Python 3.4.3 
[email protected]:/vagrant/ansible$ ansible --version 
ansible 2.2.0.0 
    config file = /vagrant/ansible/ansible.cfg 
    configured module search path = Default w/o overrides 

特拉维斯Ansible和Python版本:

$ python --version 
Python 3.4.2 
$ ansible --version 
ansible 2.2.0.0 
    config file = 
    configured module search path = Default w/o overrides 

我已经验证了LANG在两个地方都是en_US.UTF-8

这里是我的剧本:

--- 
    - hosts: localhost 
    roles: 
     - role: terraform 
     terraform_install_root: "{{ ansible_env.HOME }}/terraform/" 
     bin_dir: "{{ ansible_env.HOME }}/.local/bin" 

这里是roles/terraform/tasks/main.yml

--- 
- name: create terraform directory 
    file: path={{ terraform_install_root }}/{{ terraform_version }} state=directory 

- name: install terraform 
    unarchive: 
    copy: no 
    src: "https://releases.hashicorp.com/terraform/{{ terraform_version }}/terraform_{{ terraform_version }}_linux_amd64.zip" 
    dest: "{{ terraform_install_root }}/{{ terraform_version }}" 
    creates: "{{ terraform_install_root }}/{{ terraform_version }}/terraform" 

- name: ensure bin directory exists 
    file: path={{ bin_dir }} state=directory 

- name: create terraform symlink 
    file: src={{ terraform_install_root }}/{{ terraform_version }}/terraform dest={{ bin_dir }}/terraform state=link 

这里是roles/terraform/vars/main.yml

--- 
terraform_version: "0.7.13" 
terraform_install_root: /opt/terraform/ 
bin_dir: /usr/local/bin 

看来,由于某种原因,Ansible未能转换东西到UTF-8,即使我没有做任何事情nge和什么在本地运行就好了不是在Travis上运行。

而且,它似乎有在这些文件中没有非ASCII字符:

$ file -i ansible/roles/terraform/tasks/main.yml 
ansible/roles/terraform/tasks/main.yml: text/plain; charset=us-ascii 
$ file -i ansible/roles/terraform/vars/main.yml 
ansible/roles/terraform/vars/main.yml: text/plain; charset=us-ascii 
$ file -i ansible/travis-playbook.yml 
ansible/travis-playbook.yml: text/plain; charset=us-ascii 

任何想法?

+0

错误消息是您声明的* *相反,该字符串必须是Unicode字符串,而不是UTF-8编码的字节。 –

+0

@MarkRansom我已经更新了票证,任何文件中都没有非ASCII字符。 –

+0

非ASCII应该不重要。某处某处缺少解码或放入额外的编码。 –

回答

0

使用引号围绕这一任务的src

- name: install terraform 
    unarchive: 
    copy: no 
    src: "https://releases.hashicorp.com/terraform/{{ terraform_version }}/terraform_{{ terraform_version }}_linux_amd64.zip" 
    dest: "{{ terraform_install_root }}/{{ terraform_version }}" 
    creates: "{{ terraform_install_root }}/{{ terraform_version }}/terraform" 

然后运行它:

ansible-playbook -i 192.168.33.33, terraform.yml                2 ↵ 

PLAY [all] ********************************************************************* 

TASK [setup] ******************************************************************* 
ok: [192.168.33.33] 

TASK [terraform-stackoverflow : create terraform directory] ******************** 
ok: [192.168.33.33] 

TASK [terraform-stackoverflow : install terraform] ***************************** 
changed: [192.168.33.33] 

TASK [terraform-stackoverflow : ensure bin directory exists] ******************* 
changed: [192.168.33.33] 

TASK [terraform-stackoverflow : create terraform symlink] ********************** 
changed: [192.168.33.33] 

PLAY RECAP ********************************************************************* 
192.168.33.33    : ok=5 changed=3 unreachable=0 failed=0 
+0

我已经这样做了,但仍然失败。 –

+0

我正在使用python2.7,你能否检查我至少需要Python 3.4的 –

+0

。我已经尝试过Python 3.4和3.5,并且都看不到。 –

0

既是一个虎头蛇尾的,因为这是我更新为使用Travis的trusty( Ubuntu 14.04)映像测试版,问题消失了。

需要注意的是,precise是Ubuntu 12.04,它是四个,五岁即将到来。

0

这是一个已知的Ansible错误(#5791),并已在develop中修复,尽管它尚未发布(commit ansible/[email protected])。

也许你可以在目标主机上安装一个单独的2.7 Python来使用Ansible? (你可以配置解释器与ansible_python_interpreterinventory中一起使用。)我发现尝试在Ansible中使用Python3是一个永不结束的重击游戏,尽管平心而论Ansible正在积极地解决这个问题。

相关问题