Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ansible/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ansible将特定文件从专用git存储库复制到远程服务器(不使用ssh)的任何替代方法_Git_Ansible_Copy_Gitlab - Fatal编程技术网

使用Ansible将特定文件从专用git存储库复制到远程服务器(不使用ssh)的任何替代方法

使用Ansible将特定文件从专用git存储库复制到远程服务器(不使用ssh)的任何替代方法,git,ansible,copy,gitlab,Git,Ansible,Copy,Gitlab,我的问题是,我想用ansible将特定文件从私有git存储库复制到远程服务器,但我不想使用ssh密钥。你知道其他方法吗,比如使用api密钥?就像下面的代码示例一样,我遇到了权限问题,所以我想添加api密钥或其他内容来获取repo文件 --- - name: Sample hosts: localhost connection: local become: true tasks: - name: Copy become: yes git:

我的问题是,我想用ansible将特定文件从私有git存储库复制到远程服务器,但我不想使用ssh密钥。你知道其他方法吗,比如使用api密钥?就像下面的代码示例一样,我遇到了权限问题,所以我想添加api密钥或其他内容来获取repo文件

---
- name: Sample
  hosts: localhost
  connection: local
  become: true
  tasks:
   - name: Copy
     become: yes
     git:
        repo: 'https://gitlab.com/sample-project/branch-a/sample.xml'
        dest: "/home/sample-file"
你可以用

  • 部署令牌,请参阅
  • 在URL凭据中,请参阅
  • 如果您使用的是Gitlab CI,则屏蔽环境变量来存储令牌可能会很有用,请参阅。否则,请参阅Vault中的变量

因此,当我尝试使用类似
repo:https://userA:sampleUBFuhb24hfagb48234@gitlab.com/sample project/branch-a/sample.xml“
我现在遇到这样的错误\n致命:无法通过重定向更新url库:我是否为用户名和令牌编写了正确的语法?该错误意味着@后面的部分不能理解为有效的repo。尝试使用
version:branch-a
指定分支,或者切换到
命令:git archive…
任务,而不是
git:…
,因为您需要单个文件。在@gitlab part之后编辑,现在就可以了,谢谢。
---
- name: Sample
  hosts: localhost
  connection: local
  become: true
  tasks:
   - name: Copy
     become: yes
     git: 
       repo: "https://{{ username| urlencode }}:{{ deploy_token | urlencode }}@gitlab.com/sample-project/branch-a/sample.xml"
       dest: /home/sample-file