2017-08-22 25 views
-2

我想從github下載golang包。這是我的劇本看起來像無法通過使用可以下載golang存儲庫

- name: Fetch latest gogs repository 
     shell: "go get -u github.com/gogits/gogs" 
     become: true 
     become_user: git 

它扔了我以下錯誤:

{ 
    "changed": true, 
    "cmd": "go get -u github.com/gogits/gogs", 
    "delta": "0:00:00.002695", 
    "end": "2017-08-22 10:50:02.984669", 
    "failed": true, 
    "invocation": { 
     "module_args": { 
      "_raw_params": "go get -u github.com/gogits/gogs", 
      "_uses_shell": true, 
      "chdir": null, 
      "creates": null, 
      "executable": null, 
      "removes": null, 
      "warn": true 
     } 
    }, 
    "rc": 127, 
    "start": "2017-08-22 10:50:02.981974", 
    "stderr": "/bin/sh: go: command not found", 
    "stderr_lines": [ 
     "/bin/sh: go: command not found" 
    ], 
    "stdout": "", 
    "stdout_lines": [] 
} 

當我想這個

- name: Fetch latest gogs repository 
     shell: "go get -u {{ gogs_repo }}" 
     environment: 
     - PATH: $PATH:/usr/local/go/bin:/usr/bin 
     - GOPATH: "{{gogs_home}}/{{ gogs_project_directory }}/src" 
     - GOBIN: "{{gogs_home}}/{{ gogs_project_directory }}/bin" 
     become: true 
     become_user: git 

我得到這個錯誤

fatal: [atul-ec2]: FAILED! => { 
    "changed": false, 
    "failed": true, 
    "module_stderr": "Shared connection to ec2-13-126-203-235.ap-south-1.compute.amazonaws.com closed.\r\n", 
    "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_gntmXa/ansible_module_command.py\", line 220, in <module>\r\n main()\r\n File \"/tmp/ansible_gntmXa/ansible_module_command.py\", line 163, in main\r\n os.chdir(chdir)\r\nOSError: [Errno 13] Permission denied: '/home/ec2-user/goprojects/src/src/github.com/gogits/gogs'\r\n", 
    "msg": "MODULE FAILURE", 
    "rc": 1 
} 

這裏我的變量是

--- 
    go_version: go1.7.linux-amd64.tar.gz 
    go_url: https://storage.googleapis.com/golang/{{ go_version }} 
    go_hash: sha256:702ad90f705365227e902b42d91dd1a40e48ca7f67a2f4b2fd052aaa4295cd95 
    go_project_dir: goprojects 
    go_home: "{{ ansible_env.HOME }}" 
    gogs_home: "/home/git" 
    gogs_project_directory: "git.varadev.com" 
    gogs_repo: github.com/gogits/gogs 

但是,當我用我的服務器

which go 

在下面的命令,我得到這個

/usr/local/go/bin/go 

,當我嘗試手動go get -u github.com/gogits/gogs,這是工作的罰款。

+1

聽起來好像程序調用Go沒有配置正確的'$ PATH',或者它可能忽略了'$ PATH'變量。 – Flimzy

+0

@Flimzy然後我的'''去'''和'''得到'''命令工作 –

+3

因爲你沒有在同一個程序中執行'which go',所以你從你的shell執行它,你的shell有適當的路徑。 – Flimzy

回答

1

希望這可以幫助你爲起點:如果這樣的作品則只是稍後再試遠程

ansible-playbook gogs.yml -i localhost, 

--- 
- hosts: all 
    connection: local 

    tasks: 
    - name: check go version 
    command: go version 
    register: result 
    changed_when: no 
    ignore_errors: true 

    - set_fact: 
     go_path: "{{ lookup('env', 'GOPATH') | default(ansible_env.HOME+'/go', true) }}" 
    when: not result|failed 

    - name: go get gogs 
    shell: go get -u github.com/gogits/gogs 
    environment: 
     GOPATH: "{{ go_path }}" 
    register: gogs 
    when: not result|failed 

    - debug: var=gogs 

試圖將遠程服務器上通過鍵入運行此。

通常你不想這樣做,因爲你想通過ssh遠程執行這個操作,但是由於你已經嘗試過,並且出現了一些錯誤,所以可能通過本地嘗試connection: local可能有助於更詳細地調試此問題。

+0

ThanksModified問題。但通過設置所有的環境值,我可以downlad –

+0

你運行它的服務器?輸出是什麼? – nbari

+0

當我明確設定環境值時,每件事都很順利 –

相關問題