Ansible设置了Rails VPS

时间:2015-12-13 11:35:40

标签: unix ubuntu ssh ansible vps

我正在使用Ansible设置VPS。这是我的build_server yaml文件:

---
- 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密钥,所以我肯定应该已经获得授权了吗?我的create deploy用户任务是:

- 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

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您的部署用户没有无密码sudo(psu),因此一旦尝试执行需要权限提升的任何操作,就会提示Ansible输入用户密码。由于您没有通过CLI或变量提供,因此Ansible将失败。

要解决此问题,请通过CLI或变量指定部署用户的密码,或将sudoers文件任务更改为以下内容:

{{ deploy }} ALL=(ALL:ALL) ALL'