title: use Ansible to connect over JumpServer within Gitlab CI
body: <p>I want to configure private VMs which are reachable over bastion host.
  So I am using ubuntu 20.04 image, then I install python and all related libraries and after that I create virtual environment and install Ansible.</p>
  
  <pre><code>stages:
    - configure
  
  configure:
    image: ubuntu:20.04
    stage: configure
    before_script:
      - apt-get -y update
      - addgroup deploy
      - mkdir /opt/.env
      - chgrp -R deploy /opt/.env    
      - chmod -R 770 /opt/.env
      - apt install -y build-essential libssl-dev libffi-dev python3-dev
      - apt install -y python3-pip
      - apt install -y python3-venv
      - apt install git -y
      - python3.8 -m venv /opt/.env/basic --system-site-packages
      - source /opt/.env/basic/bin/activate
      - pip install wheel
      - pip install ansible
    script:
      - source /opt/.env/basic/bin/activate
      - echo $my_ssh_key &gt;&gt; .ssh/my_ssh_key.pem
      - chmod 400 .ssh/my_ssh_key.pem
      - mv .ssh /root/.ssh,
      - mv .ansible.cfg /root/.ansible.cfg
      - echo $(ansible --version)
      - ansible-playbook ansible/playbooks/start.yml
  
  
  </code></pre>
  
  <p>my repo structure is as following:</p>
  
  <pre><code>.ssh
     |_ ansible.cfg
  
  ansible
     |_ playbooks
  
  .ansible.cfg
  
  .gitlab-ci.yml
  </code></pre>
  
  <p>the content of .ansible.cfg:</p>
  
  <pre><code>[ssh_connection]
  ssh_args = -F /root/.ssh/ansible.cfg -o ControlMaster=auto -o ControlPersist=60m
  control_path = /root/.ssh/ansible-%%r@%%h:%%p
  </code></pre>
  
  <p>the content of .ssh/.ansible.cfg:</p>
  
  <pre><code>Host BASTION
      HostName x.x.xx.x
      User ec2-user
      IdentityFile /root/.ssh/my_ssh_key.pem
      ControlMaster auto
      ControlPath /root/.ssh/ansible-%r@%h:%p
      ControlPersist 5m
      StrictHostKeyChecking=no
      UserKnownHostsFile=/dev/null
  
  
  Host 10.*
      User ec2-user
      IdentityFile /root/.ssh/my_ssh_key.pem
      stricthostkeychecking=no
      ProxyJump BASTION
  </code></pre>
  
  <p>However, I recive the following error when the ansible script excuted:</p>
  
  <pre><code> fatal: [10.1.8.58]: UNREACHABLE! =&gt; {
       "changed": false,
       "msg": "Failed to connect to the host via ssh: kex_exchange_identification: Connection closed by remote host",
       "unreachable": true
   }
  </code></pre>
  
  <p>adding user to the ansible run command did not change anything (<code>ansible-playbook ansible/playbooks/start.yml -u ec2-user</code>)</p>
  
  <p>Have anyone faced a similar issue? I am out of idea right now, I'll appreciate any ideas.</p>