Answers: <p>This should be doable by overriding the underlying SSH options.</p>
  <p>Add something like this in your ansible.cfg file:</p>
  <pre><code>[ssh_connection]
  ssh_args = -F ~/.ssh/custom_ssh_config
  </code></pre>
  <p><code>man ssh</code>:</p>
  <pre>
         -F configfile
                 Specifies an alternative per-user configuration file.  If a configuration file is given on the command line, the system-wide configuration file (/etc/ssh/ssh_config) will  be
                 ignored.  The default for the per-user configuration file is ~/.ssh/config.  If set to “none”, no configuration files will be read.
  </pre>
  <p>Use <code>/etc/ssh/ssh_config</code> as a template and add your own customizations.
  Basically you'll have to uncomment a few lines at least like <code>IdentityFile</code> or <code>UserKnownHostsFile</code>. Untested but you get the idea. I suggest to test the <code>-F</code> option in SSH first. When you've got the SSH config right, adapt your Ansible config file.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-07-30T15:25:53.027Z
Answers: 2024-07-30T15:25:53.027Z
Answers: Kate
Body: <p>When I verbosely launch ansible with <code>ansible-playbook -vvvv -i inventory.yml  directories.yml</code> in middle of output I can see:</p>
  <pre><code>debug3: hostkeys_foreach: reading file &quot;/home/freq/.ssh/known_hosts&quot;$
  debug3: record_hostkey: found key type ECDSA in file /home/freq/.ssh/known_hosts:52$
  debug3: load_hostkeys: loaded 1 keys from 2.2.2.1$
  debug1: Host \'2.2.2.1\' is known and matches the ECDSA host key.$
  </code></pre>
  <p>How do I set ansible's config file(s) to make ansible to ignore <code>$HOME/.ssh/</code> and take ssh's <code>config</code> and <code>known_hosts</code> from location of my choice?</p>
  
Tags: <ansible><ssh>
Title: how to force ansible to ignore $HOME/.ssh
UserDisplayName: linux_beginner
ThreadText: # how to force ansible to ignore $HOME/.ssh
  
  (Asked by: username_0 on 2024-07-29)
  
  When I verbosely launch ansible with `ansible-playbook -vvvv -i inventory.yml directories.yml` in middle of output I can see:
  
  ```
  debug3: hostkeys_foreach: reading file "/home/freq/.ssh/known_hosts"$
  debug3: record_hostkey: found key type ECDSA in file /home/freq/.ssh/known_hosts:52$
  debug3: load_hostkeys: loaded 1 keys from 2.2.2.1$
  debug1: Host \'2.2.2.1\' is known and matches the ECDSA host key.$
  
  ```
  
  How do I set ansible's config file(s) to make ansible to ignore `$HOME/.ssh/` and take ssh's `config` and `known_hosts` from location of my choice?
  
  **Tags:** ansible, ssh
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-07-30. Score: 1 | Accepted answer
  
  This should be doable by overriding the underlying SSH options.
  
  Add something like this in your ansible.cfg file:
  
  ```
  [ssh_connection]
  ssh_args = -F ~/.ssh/custom_ssh_config
  
  ```
  
  `man ssh`:
  
  ```
  
         -F configfile
                 Specifies an alternative per-user configuration file.  If a configuration file is given on the command line, the system-wide configuration file (/etc/ssh/ssh_config) will  be
                 ignored.  The default for the per-user configuration file is ~/.ssh/config.  If set to “none”, no configuration files will be read.
  
  ```
  
  Use `/etc/ssh/ssh_config` as a template and add your own customizations.
  Basically you'll have to uncomment a few lines at least like `IdentityFile` or `UserKnownHostsFile`. Untested but you get the idea. I suggest to test the `-F` option in SSH first. When you've got the SSH config right, adapt your Ansible config file.
  
  
  ---
  
  