2015-12-13 88 views
0

我正在使用Ansible設置VPS。這是我的build_server YAML文件:Ansible設置Rails VPS

--- 
- hosts: do_server 
    vars_files: 
    - vars/defaults.yml 
    sudo: yes 
    remote_user: root 
    roles: 
    - { role: create-deploy-user, tags: ['create-deploy-user'] } 


- hosts: do_server 
    vars_files: 
    - vars/defaults.yml 
    remote_user: "{{ deploy }}" 
    gather_facts: no 
    roles: 
    ### Server provisioning roles: 
    - { role: linux-prereqs, tags: ['linux-prereqs'] } 
    - { role: postgresql, tags: ['postgresql'] } 
    - { role: rbenv, tags: ['rbenv'] } 
    - { role: ruby, tags: ['ruby'] } 
    - { role: nginx-passenger, tags: ['nginx-passenger'] } 

    ### Site specific roles: 
    - { role: prepare_site, tags: ['prepare_site'] } 

它一起去的文件,直到它得到了Linux-prereqs作用。在這裏我得到一個錯誤:「失蹤成爲密碼」。

我有點困惑,因爲我沒有爲我的「部署」用戶設置密碼,並且將我的SSH密鑰添加到它作爲創建用戶的一部分,因此肯定我應該已經被授權?我的創建部署用戶任務是:

- name: create {{ deploy }} user 
    user: 
    name: "{{ deploy }}" 
    comment: "deploy user" 
    generate_ssh_key: yes 
    state: present 
    shell: /bin/bash 

- name: authorize my SSH key to access {{ deploy }} 
    authorized_key: 
    key: "{{ lookup('file', '/Users/neil/.ssh/id_rsa.pub') }}" 
    user: "{{ deploy }}" 
    state: present 

- name: add {{ deploy }} to sudoers 
    lineinfile: "dest=/etc/sudoers state=present line='{{ deploy }} ALL=(ALL:ALL) ALL'" 

- name: create www-data group 
    group: 
    name: www-data 
    state: present 

任何想法?

回答

0

您的部署用戶沒有無密碼sudo({{ deploy }} ALL=(ALL:ALL) ALL'),因此一旦它嘗試執行需要特權升級的任何操作,就會提示用戶輸入密碼。由於您沒有通過CLI或作爲變量提供,Ansible將會失敗。

爲了解決這個問題無論是通過CLI或變量指定部署用戶的密碼或改變你的sudoers文件的任務如下:

- name: add {{ deploy }} to sudoers 
    lineinfile: "dest=/etc/sudoers state=present line='{{ deploy }} ALL=(ALL) NOPASSWD:ALL'"