编辑:这似乎会影响我添加 prefix_to
属性的任何任务,而不仅仅是 uri
模块。
编辑 2:四舍五入 - 在我制作的测试手册中删除 become: yes
修复了它。实际的剧本需要超级用户权限,所以它不能解决这个问题,但它可能有助于弄清楚发生了什么!
作为背景 - 我正在尝试部署 rke2 using Rancher's Ansible role。我发现一个特定的任务挂了,所以把它拉到一个独立的剧本中。
当我运行它时,注释掉 delegate_to
成功:
---
- name: test failing task
hosts: rke2_cluster
become: yes
vars:
rke2_channel: "stable"
tasks:
- name: TARBALL | Get full version name url
uri:
url: https://update.rke2.io/v1-release/channels/{{ rke2_channel }}
follow_redirects: all
register: rke2_version_url
# delegate_to: 127.0.0.1
- name: print url
debug:
msg: "{{ rke2_version_url.url }}"
输出:
ansible-playbook -i inventories/development/rke2_dev.yml -K -u ansible playbooks/development/rke2_test.yml
[DEPRECATION WARNING]: Ansible will require Python 3.8 or newer on the controller starting with Ansible 2.12. Current version: 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0]. This feature will be removed from
ansible-core in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
BECOME password:
PLAY [test failing task] ************************************************************************************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************************************************************************
ok: [10.10.77.68]
TASK [TARBALL | Get full version name url] ******************************************************************************************************************************************************************************
ok: [10.10.77.68]
TASK [print debug] ******************************************************************************************************************************************************************************************************
ok: [10.10.77.68] => {
"msg": "https://github.com/rancher/rke2/releases/tag/v1.21.3+rke2r1"
}
PLAY RECAP **************************************************************************************************************************************************************************************************************
10.10.77.68 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
但是,如果我取消对 delegate_to
的注释(据我所知,它使命令在运行 ansible 的机器上运行),它会挂在 Get full version name url
步骤并且永远不会超时:>
(带有-vvv
)
TASK [TARBALL | Get full version name url] ***************************************************************************************************************************************************************************************
task path: /home/username/repo/playbooks/development/rke2_test.yml:8
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: username
<127.0.0.1> EXEC /bin/sh -c 'echo ~username && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/username/.ansible/tmp `"&& mkdir "` echo /home/username/.ansible/tmp/ansible-tmp-1627533289.9444108-1997530-278576600249387 `" && echo ansible-tmp-1627533289.9444108-1997530-278576600249387="` echo /home/username/.ansible/tmp/ansible-tmp-1627533289.9444108-1997530-278576600249387 `" ) && sleep 0'
Using module file /home/username/repo/venv/lib/python3.6/site-packages/ansible/modules/uri.py
<127.0.0.1> PUT /home/username/.ansible/tmp/ansible-local-1997470y4pvg7my/tmp1t0q1uen TO /home/username/.ansible/tmp/ansible-tmp-1627533289.9444108-1997530-278576600249387/AnsiballZ_uri.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/username/.ansible/tmp/ansible-tmp-1627533289.9444108-1997530-278576600249387/ /home/username/.ansible/tmp/ansible-tmp-1627533289.9444108-1997530-278576600249387/AnsiballZ_uri.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S -p "[sudo via ansible, key=ysckktxpcgauzytljfjbljwgnujzabqy] password:" -u root /bin/sh -c '"'"'echo BECOME-SUCCESS-ysckktxpcgauzytljfjbljwgnujzabqy ; /home/username/repo/venv/bin/python3 /home/username/.ansible/tmp/ansible-tmp-1627533289.9444108-1997530-278576600249387/AnsiballZ_uri.py'"'"' && sleep 0'
这发生在我尝试过的所有远程主机上。我可以确认ansible主机可以连接到远程服务器:
» nc -zv -w 1 update.rke2.io 443
Connection to update.rke2.io 443 port [tcp/https] succeeded!
» curl https://update.rke2.io/v1-release/channels/stable
<a href="https://github.com/rancher/rke2/releases/tag/v1.21.3+rke2r1">Found</a>.
这是 ansible uri
模块中的错误还是其他原因?谁能重现这个?
ansible 版本:
ansible [core 2.11.2]
config file = /home/username/repo/ansible.cfg
configured module search path = ['/home/username/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /home/username/repo/venv/lib/python3.6/site-packages/ansible
ansible collection location = /home/username/.ansible/collections:/usr/share/ansible/collections
executable location = /home/username/repo/venv/bin/ansible
python version = 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0]
jinja version = 3.0.1
libyaml = True