douruhu4282 2017-08-22 11:05
浏览 152
已采纳

无法通过Ansible下载Golang存储库

I am trying to download a golang package from github. This is how my playbook looks like

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

It is throwing me following error:

{
    "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": []
}

When I am trying this

- 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

I got this error

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.
", 
    "module_stdout": "Traceback (most recent call last):
  File \"/tmp/ansible_gntmXa/ansible_module_command.py\", line 220, in <module>
    main()
  File \"/tmp/ansible_gntmXa/ansible_module_command.py\", line 163, in main
    os.chdir(chdir)
OSError: [Errno 13] Permission denied: '/home/ec2-user/goprojects/src/src/github.com/gogits/gogs'
", 
    "msg": "MODULE FAILURE", 
    "rc": 1
}

Here my variables are

---
  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

But when i am using following command on my server

which go

I got this

/usr/local/go/bin/go

and when I try manually go get -u github.com/gogits/gogs, it is working fine.

  • 写回答

1条回答 默认 最新

  • dongzinen1061 2017-08-22 20:07
    关注

    Hope this can help you as a start point:

    ---
    - 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
    

    Try to run this on your remote server by typing:

    ansible-playbook gogs.yml -i localhost,
    

    If that works then just later try remotely.

    Normally you don't want to do this since you want to execute this remotely over ssh, but since you had tried so far and are getting some errors, probably by trying locally connection: local could help to debug more in details this issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么