2016-06-22

adding authorized keys using ansible


You can use jinja template engine to set this

vars:
  ssh_user_key:
    - user: ritesh
      exclusive: no
      keys:
        - ritesh.centos
        - ritesh.fedora

- name: ssh user key upload
  authorized_key:
    user: "{{ item.user }}"
    exclusive: "{{ item.exclusive if item.exclusive is defined else 'no' }}"
    key: "{% for file_name in item['keys'] %} {{ key|default('') + lookup('file', file_name) }}{% if not loop.last %}{{ '\n' }}{% endif %} {% endfor %}"
  become_user: "{{ item.user }}"
  become: yes

  with_items:
    - "{{ ssh_user_key }}"
  tags:
    - setup-user-ssh-client-key



No comments:

Post a Comment

GitLab runner on Windows with bash shell on windows contianer on Docker

As part of your pipeline, you may need to perform browser testing across different platforms/environments. To minimize testing time, it'...