Ansible 批量推送ssh公钥到远程节点

---
- hosts: '{{ host }}'
  user: root
  tasks:

  #- name: 推送公钥到远程节点
  #参考 https://docs.ansible.com/ansible/latest/collections/ansible/posix/authorized_key_module.html
  #  ansible.posix.authorized_key:
  #    user: root
  #    state: present
  #    key: "{{ item }}"
  #  loop:
  #    - "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEA03vrPa958Eb0XllsLGGpL5ZChcW+Sw7CFFKXMdlzRqyxcoSbqKSrverkzn9RTcwsnur7sLTnAZCK/mzD1+i5p+r69qEe6mdd0qUVh/9r5Teyude77fWwPnZgzqex2b+Thh6ovWHbId2AAAVBKb9pZs2hy6G4/HuXfKWnlOxOUppQ/a4GHHlDkWOM/iJvRA2NTER3Gs8UlzUIDjQiSRoIdO776iMwYj+H7DR7he0r4SFd4LfNh+hsjqCMDQ0mI/Vu7G20G/VfSjqZi5kCRDezetii1W3Y5PnYuK5iEYeuJ+t3P3mY2eIHdTLMF2PW7yQ3NQodL9Ml5OQdwdbRu48xwtriw5VFUy01yZLgwqkby/fJg+5K0gunVtSy1Y3gmr/OV/U1hcnu4t4bPGYvnOU0t9+HG+txb8ovqoAAGaz/sERp7uX4wJNUkV3/HlRN+P/gJ1FET0jycS7YPCAQsEAqXUPLOv9yzfbZ772qN0G5VbO/hehZ31DSRqZiqlVCJxrh6CC6dekoiUbQ2Gq+2nmX7J4pgz67FYLS1fbM+p3TmyWlhFLq/cONYAZ/Wkrz5+iTM30Lyj/ocFfHto7Wj0Vwi1QlIZKjKu35gQfRJ/h9eXSU6tlZDcVPZssdlxHRO3pBytMkKYqQJ1ektfbz4lcUP/bBg8He5YG2luzn04Cadn0= root@LookBack_20220521"
  #    - "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAsZbkdSRXgWAbUZIa6T66BN7VU2P7zj50akB0G0yu93X2KFHQTGkLypXSI+vihzqHLF4I2X7Cdp+H3bdf7KLrNxokmZw5o6P2uYxxUonfhqwikaHMC/98oEg7XT+9a3vx8XKbohbsgUIU5/knR8yj4UWSEgJm2CW7yH89F90xwZOYT9ql5nZWqFxykQJn++1Q3fRgO0HzEo23SiSXKihOtWsT8Ywx5bX5rMwAjQBNOyTMnIbKuXQhh72JP+kDs2eIJn44OisWRXSaRI56WB90M0CZVmPYDRM3NqIdtxDoUu2M7LD12T6GYGyS+e5LjVSn+f7Ho0pTX2q+bUNBBJX63QgW/lQi1Mj6knNYG4CfvzMqGiGYqpiwwUPa5KEyfq9tBgxGTOo2Jt1s2o8a8U47xgG2Hsc9pz9QYuOlSUJKdX7n0L2FeYcuYWneZyE4qNb6112gapZdTdHFBdIatLAYN+al4aVjTA7+1aMsaqLHH89jnYG7py9KXeuoY7nGI+nqqJJ+6oDfNkRo4Ad7AdLsXcz2db20rex8Aa/0OpUmCYR6+4hIO9G2v862HBab2er5Rm4E69D2gW7cViFn73DJr1Vc5Au3WSnaEPEqnhp0AweyFw7JKp3dym4ZC/OhJJiyHg6QZ32g131+qps4FHGfkfVjOX4DxZ10otv22QPC+/s= root@Jenkins_20210125"

  - name: 推送Benyoo公钥到远程节点且删除其他公钥
    ansible.posix.authorized_key:
      user: root
      key: "{{ lookup('file', '~/OneDrive/RSA/LookBack_20220521.pub') }}"
      state: present
      exclusive: True

  # - name: 推送Jenkins公钥到远程节点
  #   ansible.posix.authorized_key:
  #     user: root
  #     state: present
  #     key: '{{ item }}'
  #   with_file:
  #     #- ~/OneDrive/RSA/LookBack_20220521.pub
  #     - ~/OneDrive/RSA/id_rsa_Jenkins_20210125.pub

  #参考 https://www.zhukun.net/archives/8167
  #- name: 推送公钥到远程节点
  #  copy: src=~/OneDrive/RSA/20220522_0500_ssh_public_key.pub dest=/root/.ssh/authorized_keys  owner=root group=root mode=400 backup=yes follow=yes
lookback
  • 本文由 发表于 2022年5月23日04:33:07
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: