ansible

Execute playbook from localhost through bastion host


We are doing our deployments via Ansible and a bastion host is provisioned for the deployments.

The current approach I am using is to clone the Ansible repo in the bastion host and run the commands from that host.

My question is: is it possible to run the Ansible playbook from my local machine through the bastion host?

(Basically, avoid cloning the repository in the bastion host.)


Solution

  • Let's say you want to provision a couple of VMs 172.20.0.10 and 172.20.0.11 in your development environment going through your 172.20.0.1 bastion. Your inventory looks a bit like this

    [development]
    172.20.0.10
    172.20.0.11
    

    Then you can edit your ~/.ssh/config and add

    Host bastion
        Hostname 172.20.0.1
        User youruser
    
    Host 172.20.*
        ProxyJump bastion
        User youruser
    

    Then you can test a ssh 172.20.0.10 that should land you in your first VM. If it works for SSH, Ansible should work the same.

    Note, you can run ansible with -vvv (or is it one more v, not sure atm), you'll see the SSH commands Ansible is running.

    Note 2, ProxyJump requires a recent OpenSSH, 6.7 at least if I remember correctly