【问题标题】:Ansible task to copy SSH keys复制 SSH 密钥的 Ansible 任务
【发布时间】:2021-06-04 22:47:55
【问题描述】:

我有一个包含 6 个节点的 Cassandra 集群,这是我的 Ansible 库存文件:

[cassandra]
cassandra-01 ansible_host=192.168.2.10
cassandra-02 ansible_host=192.168.2.11
cassandra-03 ansible_host=192.168.2.12 
cassandra-04 ansible_host=192.168.2.13
cassandra-05 ansible_host=192.168.2.14
cassandra-06 ansible_host=192.168.2.15

我想将我的 SSH 密钥从 cassandra-01 复制到集群中的所有节点,并且我想使用 Ansible 任务来完成。

实现这一目标的最佳和幂等方式是什么?

附:我在 Github 上找到了这个模块 ssh-copy-id,可能会起作用吗?

【问题讨论】:

  • 关于您问题中的模块,根据文档似乎是“授权远程系统进行无密码SSH身份验证”。所以不完全是您在问题中寻找的内容。

标签: ansible


【解决方案1】:

由于我过去有类似的要求,我发现以下方法有效

- name: Copy SSH key from node 01 to all others
  synchronize:
    src: "/tmp/ssh.key"
    dest: "/tmp/ssh.key"
    mode: push
  delegate_to: cassandra-01
  check_mode: no
  when: ( ansible_host != "cassandra-01" )
  tags: distribute_keys

主要是

  • 使用模块 synchronizersync 包装器
  • 让任务仅在成员服务器上运行 (when: "cassandra-01" not in ansible_host)
  • 将任务委托给主节点
  • 从主节点推送到成员节点

【讨论】:

  • 对不起,我想打个比方 ssh-copy-id
猜你喜欢
  • 1970-01-01
  • 2017-02-27
  • 2016-08-15
  • 1970-01-01
  • 1970-01-01
  • 2017-07-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多