我开始使用Ansible。我的Ansible主机和远程目标都是Ubuntu 16.04。我尝试使用ansible nginx剧本,但出现了太多错误。
这是我的剧本:
- hosts: testbed
tasks:
- name: Install the Nginx Repository
apt_repository:
repo: ppa:nginx/stable
state: present
become: yes
become_method: sudo
这是我的主机文件:
[testbed]
myserveripaddr.compute-1.amazonaws.com
[testbed:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_become_pass=mydeployer_pswd
ansible_become_user=mydeployer
我正在使用以下命令行执行ansible:
ansible-playbook base.yml -vvv
这是我得到的错误:
<myserveripaddr.compute-1.amazonaws.com> ESTABLISH SSH CONNECTION FOR USER: None
<myserveripaddr.compute-1.amazonaws.com> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/manish/.ansible/cp/ec8ae2c055 myserveripaddr.compute-1.amazonaws.com '/bin/sh -c '"'"'rm -f -r /var/tmp/ansible-tmp-1531936359.43-119337047930812/ > /dev/null 2>&1 && sleep 0'"'"''
<myserveripaddr.compute-1.amazonaws.com> (0, '', '')
fatal: [myserveripaddr.compute-1.amazonaws.com]: FAILED! => {
"changed": false,
"cmd": "apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 8B3981E7A6852F782CC4951600A6F0A3C300EE8C",
"invocation": {
"module_args": {
"codename": null,
"filename": null,
"install_python_apt": true,
"mode": null,
"repo": "ppa:nginx/stable",
"state": "present",
"update_cache": true,
"validate_certs": true
}
},
"msg": "gpg: requesting key C300EE8C from hkp server keyserver.ubuntu.com\ngpg: key C300EE8C: public key \"Launchpad Stable\" imported\ngpg: Total number processed: 1\ngpg: imported: 1 (RSA: 1)\ngpg: no writable keyring found: eof\ngpg: error reading `[stdin]': general error\ngpg: import from `[stdin]' failed: general error\ngpg: Total number processed: 0",
"rc": 1,
"stderr": "gpg: requesting key C300EE8C from hkp server keyserver.ubuntu.com\ngpg: key C300EE8C: public key \"Launchpad Stable\" imported\ngpg: Total number processed: 1\ngpg: imported: 1 (RSA: 1)\ngpg: no writable keyring found: eof\ngpg: error reading `[stdin]': general error\ngpg: import from `[stdin]' failed: general error\ngpg: Total number processed: 0\n",
"stderr_lines": [
"gpg: requesting key C300EE8C from hkp server keyserver.ubuntu.com",
"gpg: key C300EE8C: public key \"Launchpad Stable\" imported",
"gpg: Total number processed: 1",
"gpg: imported: 1 (RSA: 1)",
"gpg: no writable keyring found: eof",
"gpg: error reading `[stdin]': general error",
"gpg: import from `[stdin]' failed: general error",
"gpg: Total number processed: 0"
],
"stdout": "Executing: /tmp/tmp.vjwZQC7PG8/gpg.1.sh --recv-keys\n--keyserver\nhkp://keyserver.ubuntu.com:80\n8B3981E7A6852F782CC4951600A6F0A3C300EE8C\n",
"stdout_lines": [
"Executing: /tmp/tmp.vjwZQC7PG8/gpg.1.sh --recv-keys",
"--keyserver",
"hkp://keyserver.ubuntu.com:80",
"8B3981E7A6852F782CC4951600A6F0A3C300EE8C"
]
}
我需要做些什么才能使它起作用?
答案 0 :(得分:-1)
ansible_become_user
是用户“您成为”,因此您正尝试以mydeployer
用户的身份执行任务。您不能这样做,应该以{{1}}的身份运行它。
从库存中删除root
。或将其更改为ansible_become_user=mydeployer
,但这仍然是默认值。