ansible模块authorized_key

示例:

 

#  新增公钥内容到服务器用户家目录的.ssh目录的authorized_keys文件 没有则创建authorized_keys文件 state: (1) present 添加 (2) absent 删除
---
- hosts: test
  gather_facts: false
  tasks:
  - name: deliver authorized_keys
    authorized_key:
        user: root
        key: "{{ lookup('file', '/etc/ansible/roles/authorized_keys') }}"  # 从本地authorized_keys文件读取公钥内容
        state: present
        exclusive: no

 

 

 

说明:

ansible-doc authorized_key

添加或移除authorized keys为特定用户

 

Options: (= is mandatory)(= 后面的参数是强制要有的)

- exclusive [default: no]

  是否移除authorized_keys文件中其它非指定key

= key

  The SSH public key(s) 可以是字符串或url (https://github.com/username.keys)

- key_options

  附加到key中的字符串 #不加参数会删除上次带参数时添加的字符串

- path

  authorized_keys文件存放的位置 [Default: (homedir)+/.ssh/authorized_keys]

- state

  present 添加指定key到authorized_keys文件中

  absent 从authorized_keys文件中移除指定key [Default: present]

- user

  远端服务器上的用户(编辑该用户的authorized_keys文件) [Default: None]

posted @ 2016-02-17 11:58  metasequoia  阅读(8896)  评论(0编辑  收藏  举报