我使用vagrant運行Xenial 16.04 VM。虛擬機開箱即用vagrant
用戶使用vagrant密碼,但沒有密碼root
(儘管如果您將ssh插入root @ ubuntu-vm,Ubuntu仍然需要密碼) 爲了模擬生產VPS,我創建了一個deployer
用戶使用這個劇本:不能使用sudo與新創建的Ubuntu用戶通過ansible
- user:
name: deployer
groups: admin
password: "{{ deployer_password }}"
shell: /bin/bash
- name: "read authorized keys from root user"
become_user: vagrant
command: "cat ~/.ssh/authorized_keys"
register: "root_authorized_keys"
- debug: msg="{{root_authorized_keys}}"
- name: "create .ssh dir for deployer"
file: path="/home/deployer/.ssh" state=directory
- name: "copy authorized keys to deployer user"
shell: "echo '{{root_authorized_keys.stdout}}' > /home/deployer/.ssh/authorized_keys"
- name: "chown the authorized_keys file"
file: path="/home/deployer/.ssh" recurse=yes mode=0700 owner="deployer"
當我ssh到[email protected]
有人問我鍵入密碼,然後我記錄在VM作爲一個應該期望。在輸入deployer
用戶的密碼後,sudo
和sudo su
也按預期工作。
當我嘗試通過Ansible手冊或通過Ansible ad-hoc命令嘗試sudo
時,出現問題。
注意我得到以下4 Ansible響應命令:
$ ansible all -m ping -u vagrant
ubuntu-vm | SUCCESS => {
"changed": false,
"ping": "pong"
}
$ ansible all -m ping -u deployer
ubuntu-vm | SUCCESS => {
"changed": false,
"ping": "pong"
}
$ ansible all -m ping -u vagrant --sudo
ubuntu-vm | SUCCESS => {
"changed": false,
"ping": "pong"
}
$ ansible all -m ping -u deployer --sudo
ubuntu-vm | FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "sudo: a password is required\n",
"module_stdout": "",
"msg": "MODULE FAILURE"
}
我有什麼選擇使用sudo
爲deployer
成功?
還要考慮到的是,remote_user
爲ubuntu-vm
主機將是既vagrant
和deployer
用戶。如果可能的話,我想辦法在劇本同時使用(例如:我用的是vagrant
用戶創造deployer
用戶,然後我用deployer
用戶對其他戲劇)
這可以和'ansible-playbook'一起使用嗎?如果是這樣,我怎麼能通過密碼爲多個用戶? (請參閱我在上面的問題之後編寫的斜體文本) –
如果我只需要爲一個用戶傳遞密碼,但是我無法弄清楚如何爲多個用戶傳遞密碼,則「--ask-become-pass」 。 –
除非您使用Ansible保險庫,否則我認爲不可能爲多個用戶傳遞密碼。請參閱:http://serverfault.com/questions/560106/how-can-i-implement-ansible-with-per-host-passwords-securely – helloV