下面是将ssh配置应用于特定主机的过程:
- name: Add a host in the configuration
community.general.ssh_config:
ssh_config_file: "{{ ssh_config_path }}"
host: "example.com"
state: present
我们有两种ssh配置变体:ssh_config1
&ssh_config2
ssh_config1
需要应用于主机组(group1
(ssh_config2
需要应用于特定的单个主机host1.abc.com
(不在group1
中(
游戏应该如何执行此功能?
要求是应用特定的
想当然地认为:
- 此战术手册将针对您库存中的任何主机
- 您已经有一个有效的清单,其中包含
group1
、特定主机host1.abc.com
和任何其他 - 您希望跳过任何未配置
ssh_config_path
的主机的配置任务 - 您已经从环境中的任何其他位置删除了
ssh_config_path
变量的任何定义
在group_vars/group1.yml
中
---
ssh_config_path: /path/to/ssh_config1
在host_vars/host1.abc.com.yml
中
---
ssh_config_path: /path/to/ssh_config2
然后以下(未经测试的(行动手册应该符合您的要求
---
- hosts: all
gather_facts: false
tasks:
- name: Add a host in the configuration
community.general.ssh_config:
ssh_config_file: "{{ ssh_config_path }}"
host: "example.com"
state: present
when: ssh_config_path is defined
或者,如果您只想在给定的主机上使用完全相同的配置和内部任务播放上述内容,您可以简单地将上面的host:
节替换为:
hosts: group1:host1.abc.com