2016-09-23 5 views
1

私は不自然なローカルを使って、迷惑メールVMに仮想環境を作成しようとしましたが、失敗しました。可能なプレイブックでpython仮想環境を作成することは可能ですか?

これは私のベイグラントファイルです。これは、 "playbook.yml"

Vagrant.configure(2) do |config| 
    config.vm.provider "virtualbox" do |v| 
    v.memory = 4096 
    v.cpus = 2 
    end 

    config.vm.define "shortener" do |shortener| 
    shortener.vm.box = "ubuntu/trusty64" 
    # database 
    shortener.vm.network :forwarded_port, host: 3307, guest: 3306 
    # browser 
    shortener.vm.network :forwarded_port, host: 4568, guest: 4568 
    shortener.vm.provision :ansible_local do |ansible| 
     ansible.playbook = "playbook.yml" 
    end 
    end 

    config.ssh.forward_agent = true 

end 

です:

- name: Deploy shortener 
    hosts: all 
    become: true 
    become_method: sudo 

    tasks: 
    - name: Install packages 
     apt: update_cache=yes name={{ item }} state=present 
     with_items: 
    - git 
    - python-pip 
    - nginx-full 
    - vim 
    - python-virtualenv 
    - virtualenvwrapper 
    - python3.4 
    - python3.4-doc 
    - python3.4-dev 
    - software-properties-common 
    - python-software-properties 
    - postgresql 
    - postgresql-client 

- name: Load virtualenvwrapper 
    shell: source /etc/bash_completion.d/virtualenvwrapper 

- name: Create virtual environment    
    shell: mkvirtualenv shortener --python=/usr/bin/python3 

- name: Install requirements 
    pip: requirements='/vagrant/configs/requirements.txt' 

が、これは '放浪アップ' の出力です:

[email protected]:~/url_shortener$ vagrant provision 
==> shortener: Running provisioner: ansible_local... 
    shortener: Running ansible-playbook... 

PLAY [Deploy shortener]  
************************** 

TASK [setup] 
************************** 
ok: [shortener] 
************************** 
TASK [Install packages] 
ok: [shortener] => (item=[u'git', u'python-pip', u'nginx-full', u'vim', u'python-virtualenv', u'virtualenvwrapper', u'python3.4', u'python3.4-doc', u'python3.4-dev', u'software-properties-common', u'python-software-properties', u'postgresql', u'postgresql-client']) 

TASK [Load virtualenvwrapper] 
************************** 
fatal: [shortener]: FAILED! => {"changed": true, "cmd": "source /etc/bash_completion.d/virtualenvwrapper", "delta": "0:00:00.003591", "end": "2016-09-23 16:06:43.169513", "failed": true, "rc": 127, "start": "2016-09-23 16:06:43.165922", "stderr": "/bin/sh: 1: source: not found", "stdout": "", "stdout_lines": [], "warnings": []} 

NO MORE HOSTS LEFT 
************************** 
[WARNING]: Could not create retry file 'playbook.retry'. [Errno 2] No such file or directory: '' 


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

Ansible failed to complete successfully. Any error output should be visible above. Please fix these errors and try again. 

また、同じ結果を持つ 'shell'の代わりに 'command'を使用しようとしました。

仮想環境を作成するシェルスクリプトを使用することはできますが、そのエラーを確実に解決することは可能でしょうか?

+1

'pip'モジュールは' virutalenv'パラメータをサポートしているので、これを別のタスク([docs](https://docs.ansible.com/ansible/pip_module.html))で行う必要はありません。 。 – jonafato

+1

私はあなたのソースがあなたのpython virtualenvをソースしているかもしれないと思う。 virtualenvをソースする代わりに、私は通常、私のプレイブックのvirtualenvから '' python''バイナリのフルパスを使います。多分 '' mkvirtualenv''への完全なパスを使うとうまくいくでしょう。 –

+0

@ notorious.no "virtualenvwrapper.sh"の関数なので、 "full path to mkvirtualenv"とはどういう意味だったのでしょうか? –

答えて

0

私は解決策を見つけました。これは私の "playbook.yml"ファイルです:

- name: Deploy shortener 
    hosts: all 
    remote_user: vagrant 

tasks: 
    - name: Install packages 
     become: true 
     become_method: sudo   
     apt: update_cache=yes name={{ item }} state=present 
     with_items: 
     - git 
     - python-pip 
     - nginx-full 
     - vim 
     - python-virtualenv 
     - virtualenvwrapper 
     - python3.4 
     - python3.4-doc 
     - python3.4-dev 
     - software-properties-common 
     - python-software-properties 
     - postgresql 
     - postgresql-client 

    - name: Install requirements 
     become: true 
     become_method: sudo   
     pip: 
     requirements: /vagrant/configs/requirements.txt 
     virtualenv: /home/vagrant/.virtualenvs/shortener 
     virtualenv_python: python3.4 

私はそれに標準のピップモジュールを使用しています。役に立つコメントありがとう!

+0

うれしい私は助けることができます。 – jonafato

関連する問題