2017-05-14 52 views
1

我有一個ansible-劇本,當我嘗試運行這個劇本我收到此錯誤 (在文件中指定行不再,也許它改變了嗎?)[ansible-playbook]指定的行不再在文件中,也許它改變了?

-- 
- name: check if the public/private key exist at ~/.ssh/ 
    stat: 
    path: /root/.ssh/id_rsa.pub 
    register: st 

- name: run the command 
    command: cat /root/.ssh/id_rsa.pub|ssh -i /root/.ssh/bi_ppc.pem [email protected]"{{items}" "cat >> .ssh/authorized_keys" 
    with_items: 
    - groups['ubuntu'] 
    when: st.changed 
~  

ansible --version

ansible 2.2.0.0 
    config file = /home/swathi/Desktop/infrastructure/ansible.cfg 
    configured module search path = Default w/o overrides 

回答

2

您可以使用authorized_key模塊,將pub文本從本地複製到遠程。

-- 
- name: get public key 
    local_action: shell cat /home/user/.ssh/id_rsa.pub 
    register: pubkey 

- name: check keys 
    debug: msg="{{ pubkey.stdout }}" 

- name: add public key on the remote server 
    authorized_key: user=root key="{{ item[0] }}" 
    delegate_to: "{{ item[1] }}" 
    with_nested: 
    - "{{ pubkey.stdout }}" 
    - "{{groups['ubuntu']}}" 
相關問題