authorized_keys在ansible中为用户设置

时间:2017-09-14 15:08:51

标签: ansible

我正在尝试创建用户并添加到authorized_keys文件。

当我尝试运行时,这是ansible代码我收到以下错误:

  

ERROR!这个任务' authorized_key'有额外的参数,只允许在以下模块中使用:command,win_command,shell,win_shell,script,include,include_vars,add_host,group_by,set_fact,raw,meta

- name: Adding user {{ user }}  
  user: name={{ user }}
        group={{ group }}
        shell=/bin/bash
        password=${password}
        groups=sudo
        append=yes
        generate_ssh_key=yes
        ssh_key_bits=2048
        ssh_key_file=.ssh/id_rsa

- name: Authorized keys
  authorized_key:
        user={{ user }}
        state=present
        manage_dir= yes
        key="{{ lookup('file', '/home/vivek/.ssh/id_rsa.pub') }}"

1 个答案:

答案 0 :(得分:0)

我怀疑问题出在这里:manage_dir= yes

使用纯YAML语法来防止key=value语法出现不同类型的问题。

- name: Authorized keys
  authorized_key:
    user: "{{ user }}"
    state: present
    manage_dir: yes
    key: "{{ lookup('file', '/home/vivek/.ssh/id_rsa.pub') }}"