How to run an ansible-playbook with a passphrase-protected-ssh-private-key?

后端 未结 3 1327
花落未央
花落未央 2021-01-30 22:26

I have an autoscaling group on Amazon EC2 and I have added my public key when I create AMI with packer so I can run ansible-playbook and ssh to the hos

3条回答
  •  礼貌的吻别
    2021-01-30 23:20

    Building up on @javeed-shakeel's answer, I added the following lines to my .bashrc:

    command -v ansible > /dev/null &&
        alias ansible='ssh-add -l > /dev/null || ssh-add 2> /dev/null && ansible'
    command -v ansible-playbook > /dev/null &&
        alias ansible-playbook='ssh-add -l > /dev/null || ssh-add 2> /dev/null && ansible-playbook'
    

    This will run ssh-add before ansible(-playbook) iff there was no key added to the ssh-agent, yet. This has the advantage that one does not need to run ssh-add by hand and one will be asked for the passphrase only if it is necessary.

提交回复
热议问题