[an error occurred while processing this directive]

Генерация конфигурации клиента OpenSSH из inventory.ini в Ansible
Часто на работе приходится разыскивать серверы, грепать из inventory.ini. Но
почему бы Ansible не позаботится о нас. Настраиваем генерацию ~/.ssh/config из inventory.ini:

   cat ssh-config.yml:
   ---
   - name: Generate ssh client configuration from ansible inventory
     hosts: localhost
     connection: local
     gather_facts: no
     vars:
       title: "EasyConfig by Ansible"
       ssh_config_path: ssh_config.txt
     tasks:
       - name: ensure config for each host of inventory exist
         template: src="ssh_config.j2" dest="{{ ssh_config_path }}"
         when: ssh_config_path != ""


   cat ssh-config.j2 :
      #### {{ title }} Begin ####
   
   {% for host in groups.all | sort() | list %}
   
   {% if host != "localitem" and host != "127.0.0.1" and host != "localhost" %}
   Host {{hostvars[host].inventory_hostname}}
   {% if hostvars[host].ansible_host is defined and hostvars[host].ansible_host != "" %}  HostName {{hostvars[host].ansible_host}}
   {% else %}  HostName {{hostvars[host].inventory_hostname}}
   {% endif %}
   {% if hostvars[host].ansible_ssh_port is defined %}  Port {{hostvars[host].ansible_ssh_port}}
   {% endif %}
   {% endif %}
   {% endfor %}
   
   # Defaults
   Host *
       User root
       Port 22

   
   #### {{ title }} End ####


Получившийся ssh_config.txt - внимательно осматриваем и добавляем (или нет)  к
своему ~/.ssh/config.

Как профит имеем автокомплит по серверам (можно добавить префикс), не тратим
время на grep hostname Passwords_Hosts.txt можем прямо из Ansible управлять процессом.
 
23.02.2020 , Автор: Ilya
Ключи: ssh, ansible, config / Лицензия: CC-BY
Раздел:    Корень / Безопасность / SSH

[an error occurred while processing this directive]

[an error occurred while processing this directive]