config-add-sshkey.yaml 505 B

12345678910111213141516171819
  1. ---
  2. - name: Add ssh key
  3. hosts: "{{ my_hosts | d([]) }}"
  4. become: true
  5. tasks:
  6. - name: Install public keys
  7. ansible.posix.authorized_key:
  8. user: "{{ lookup('env', 'USER') }}"
  9. state: present
  10. key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
  11. - name: Change sudoers file
  12. ansible.builtin.lineinfile:
  13. path: /etc/sudoers
  14. state: present
  15. regexp: '^%sudo'
  16. line: '%sudo ALL=(ALL) NOPASSWD: ALL'
  17. validate: /usr/sbin/visudo -cf %s