How do I use remote machine's SSH keys in ansible git module

前端 未结 2 1291
抹茶落季
抹茶落季 2021-02-05 09:15

I\'ve been trying to get Ansible to provision a remote machine, and I want the remote machine to be set up with its own keys, and have the ability to clone git repositories from

2条回答
  •  情话喂你
    2021-02-05 10:07

    This is how I deploy from Github using a key file set on the remote server. If the keyfile parameter for git doesn't work then something is wrong with your playbook:

    - name: Creates .ssh directory for root
      sudo: yes
      file: path=/root/.ssh state=directory
    
    # This public key is set on Github repo Settings under "Deploy keys"
    - name: Upload the private key used for Github cloning
      sudo: yes
      copy: src=keys/github dest=/root/.ssh/github
    
    - name: Correct SSH deploy key permissions
      sudo: yes
      file: dest=/root/.ssh/github mode=0600
    
    - name: Deploy site files from Github repository
      sudo: yes
      git:
        repo: git@github.com:miohtama/foobar.git
        dest: /srv/django/foobar
        key_file: /root/.ssh/github
        accept_hostkey: yes
        force: yes
    

提交回复
热议问题