我应该如何使用Ansible向Ubuntu 16.04添加存储库?

我应该如何使用Ansible向Ubuntu 16.04添加存储库?,ansible,ansible-2.x,Ansible,Ansible 2.x,我开始学习Ansible。我的Ansible主机和远程目标都是Ubuntu 16.04。我尝试使用ansible nginx playbook,但我得到了太多的错误 这是我的剧本: - hosts: testbed tasks: - name: Install the Nginx Repository apt_repository: repo: ppa:nginx/stable state: present

我开始学习Ansible。我的Ansible主机和远程目标都是Ubuntu 16.04。我尝试使用ansible nginx playbook,但我得到了太多的错误

这是我的剧本:

- 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"
    ]
}
为用户建立SSH连接:无
SSH:EXEC SSH-C-o ControlMaster=auto-o ControlPersist=60s-o KbdInteractiveAuthentication=no-o PreferredAuthentications=gssapi with mic、gssapi-keyex、基于主机、公钥-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和睡眠0”
(0, '', '')
致命:[myserveripaddr.compute-1.amazonaws.com]:失败!=>{
“更改”:错误,
“cmd”:“apt key adv--recv key--keyserverhkp://keyserver.ubuntu.com:80 8B3981E7A6852F782C6951600A6F0A3C300EE8C“,
“调用”:{
“模块参数”:{
“代码名”:空,
“文件名”:空,
“install_python_apt”:true,
“模式”:空,
“回购协议”:“购电协议:nginx/stable”,
“国家”:“目前”,
“更新缓存”:true,
“验证证书”:正确
}
}, 
“msg”:“gpg:从hkp服务器keyserver.ubuntu.com请求密钥C300EE8C\ngpg:密钥C300EE8C:公钥\“Launchpad Stable\”导入\ngpg:处理总数:1\ngpg:导入:1(RSA:1)\ngpg:未找到可写密钥环:eof\ngpg:读取“[stdin]”时出错:一般错误\ngpg:从“[stdin]导入”'失败:一般错误\ngpg:处理的总数:0',
“rc”:1,
“stderr”:“gpg:从hkp服务器keyserver.ubuntu.com请求密钥C300EE8C\ngpg:密钥C300EE8C:公钥\“Launchpad Stable\”导入\ngpg:处理总数:1\ngpg:导入:1(RSA:1)\ngpg:未找到可写密钥环:eof\ngpg:读取“[stdin]”时出错:一般错误\ngpg:从“[stdin]导入]'失败:一般错误\ngpg:处理的总数:0\n',
“标准线”:[
“gpg:从hkp服务器keyserver.ubuntu.com请求密钥C300EE8C”,
“gpg:密钥C300EE8C:公钥\“启动板稳定\”已导入”,
“gpg:处理总数:1”,
“gpg:imported:1(RSA:1)”,
“gpg:未找到可写密钥环:eof”,
“gpg:读取“[stdin]”时出错:一般错误”,
“gpg:从“[stdin]”导入失败:一般错误”,
“gpg:处理的总数:0”
], 
“stdout”:“正在执行:/tmp/tmp.vjwZQC7PG8/gpg.1.sh--recv keys\n--keyserver\nhkp://keyserver.ubuntu.com:80\N8B3981E7A6852F782C6951600A6F0A3C300EE8C\n“,
“标准线”:[
“正在执行:/tmp/tmp.vjwZQC7PG8/gpg.1.sh——recv键”,
“--keyserver”,
"hkp://keyserver.ubuntu.com:80", 
“8B3981E7A6852F782C6951600A6F0A3C300EE8C”
]
}

我需要做些什么才能让它工作

ansible\u been\u user
是“you been”用户,因此您试图以
mydeployer
用户的身份执行任务。您不能这样做,您应该以
根目录运行它

从您的库存中删除
ansible\u been\u user=mydeployer
。或者将其更改为
ansible\u been\u user=root
,但这仍然是默认值