在执行此类任务时,为了安装本地软件包( la yum localinstall):
- name: Install local packages
yum:
name="/my/path/{{ item }}"
state=installed
with_items: list_of_packages
其中list_of_packages在vars / main.yml中定义为:
---
list_of_packages:
- package1.rpm
- package2.rpm
...
Yum尝试变聪明并将所有项目放在一个命令中但结尾只添加第一个包的路径:
REMOTE_MODULE yum name =“/ my / path / package1.rpm,package2.rpm”state = installed
显然未能找到第二个包
我尝试在内部添加路径,如:{{ "/my/path/"+item }}
并继续这样做。
除了在添加基本路径的情况下复制“list_of_packages”之外,还有其他方法吗? (我正在使用的解决方法)
编辑:详细测试剧本(ansible版本1.9.2):
# cat playbooks/testlocalinstall.yml
---
- hosts: all:!localhost
vars:
list_of_packages:
- oracleasmlib-2.0.4-1.el6.x86_64.rpm
- oracleasm-support-2.1.8-1.el6.x86_64.rpm
tasks:
- name: Install Packages
yum: name=/software/{{ item }} state=installed
with_items: list_of_packages
结果:
# ansible-playbook playbooks/testlocalinstall.yml -i inventory/myinv -vvv
PLAY [all:!localhost] *********************************************************
GATHERING FACTS ***************************************************************
<testmachine> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO testmachine
<testmachine> REMOTE_MODULE setup
<testmachine> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1441783338.15-74757921814888 && echo $HOME/.ansible/tmp/ansible-tmp-1441783338.15-74757921814888'
<testmachine> PUT /tmp/tmp_955vP TO /root/.ansible/tmp/ansible-tmp-1441783338.15-74757921814888/setup
<testmachine> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /root/.ansible/tmp/ansible-tmp-1441783338.15-74757921814888/setup; rm -rf /root/.ansible/tmp/ansible-tmp-1441783338.15-74757921814888/ >/dev/null 2>&1'
ok: [testmachine]
TASK: [Install Packages] ******************************************************
<testmachine> ESTABLISH CONNECTION FOR USER: root on PORT 22 TO testmachine
<testmachine> REMOTE_MODULE yum name=/software/oracleasmlib-2.0.4-1.el6.x86_64.rpm,oracleasm-support-2.1.8-1.el6.x86_64.rpm state=installed
<testmachine> EXEC /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1441783339.35-66981904309720 && echo $HOME/.ansible/tmp/ansible-tmp-1441783339.35-66981904309720'
<testmachine> PUT /tmp/tmpF0hiqP TO /root/.ansible/tmp/ansible-tmp-1441783339.35-66981904309720/yum
<testmachine> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python -tt /root/.ansible/tmp/ansible-tmp-1441783339.35-66981904309720/yum; rm -rf /root/.ansible/tmp/ansible-tmp-1441783339.35-66981904309720/ >/dev/null 2>&1'
failed: [testmachine] => (item=oracleasmlib-2.0.4-1.el6.x86_64.rpm,oracleasm-support-2.1.8-1.el6.x86_64.rpm) => {"changed": false, "failed": true, "item": "oracleasmlib-2.0.4-1.el6.x86_64.rpm,oracleasm-support-2.1.8-1.el6.x86_64.rpm", "rc": 0, "results": []}
msg: No Package file matching 'oracleasm-support-2.1.8-1.el6.x86_64.rpm' found on system
msg:
No Package file matching 'oracleasm-support-2.1.8-1.el6.x86_64.rpm' found on system
FATAL: all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/root/testlocalinstall.retry
testmachine : ok=1 changed=0 unreachable=0 failed=1
在列表中添加每个包的路径可以正常工作
感谢。
答案 0 :(得分:1)
我无法重现此问题:
--downloadonly
yum选项(link)请试试这个:
检查Ansible版本 - 1.9.2之前的版本中存在错误(我正在测试的版本)
Yum无法找到您提供的包列表的依赖项 - 请确保使用yum --downloadonly
下载的所有包都在列表中。它们应与目标包一起明确说明。
作为一种解决方法,您可以使用模板模块创建本地yum存储库,该模块指向同一文件夹/my/path/
。默认情况下应禁用此存储库。仅在使用yum
enablerepo
---
- hosts: all
vars:
list_of_packages:
- nc-1.84-24.el6.x86_64.rpm
- telnet-0.17-48.el6.x86_64.rpm
- screen-4.0.3-18.el6.x86_64.rpm
tasks:
- name: Install Packages
yum: name=/vagrant/{{ item }} state=installed
with_items: list_of_packages
} {/ 1>
vagrant@localhost vagrant]$ sudo ansible-playbook -vvv -c local -i "localhost," test.yml
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
<localhost> REMOTE_MODULE setup
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1441656987.66-146848178907207 && echo $HOME/.ansible/tmp/ansible-tmp-1441656987.66-146848178907207']
<localhost> PUT /tmp/tmp7TIwxU TO /root/.ansible/tmp/ansible-tmp-1441656987.66-146848178907207/setup
<localhost> EXEC ['/bin/sh', '-c', u'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1441656987.66-146848178907207/setup; rm -rf /root/.ansible/tmp/ansible- tmp-1441656987.66-146848178907207/ >/dev/null 2>&1']
ok: [localhost]
TASK: [Install Packages] ******************************************************
<localhost> REMOTE_MODULE yum name=/vagrant/nc-1.84-24.el6.x86_64.rpm,telnet-0.17-48.el6.x86_64.rpm,screen-4.0.3-18.el6.x86_64.rpm,lftp-4.0.9-6.el6.x86_64.rpm state=installed
<localhost> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1441656987.78-72871194424865 && echo $HOME/.ansible/tmp/ansible-tmp-1441656987.78-72871194424865']
<localhost> PUT /tmp/tmpTy7Al1 TO /root/.ansible/tmp/ansible-tmp-1441656987.78-72871194424865/yum
<localhost> EXEC ['/bin/sh', '-c', u'LANG=C LC_CTYPE=C /usr/bin/python -tt /root/.ansible/tmp/ansible-tmp-1441656987.78-72871194424865/yum; rm -rf /root/.ansible/tmp/ansible- tmp-1441656987.78-72871194424865/ >/dev/null 2>&1']
changed: [localhost] => (item=nc-1.84-24.el6.x86_64.rpm,telnet-0.17-48.el6.x86_64.rpm,screen-4.0.3-18.el6.x86_64.rpm,lftp-4.0.9-6.el6.x86_64.rpm) => {"changed": true, "item": "nc-1.84-24.el6.x86_64.rpm, telnet-0.17-48.el6.x86_64.rpm,screen-4.0.3-18.el6.x86_64.rpm,lftp-4.0.9-6.el6.x86_64.rpm", "msg": "", "rc": 0, "results": ["Loaded plugins: fastestmirror\nSetting up Install Process\nExamining /vagrant/ nc-1.84-24.el6.x86_64.rpm: nc-1.84-24.el6.x86_64\nMarking /vagrant/nc-1.84-24.el6.x86_64.rpm to be installed\nLoading mirror speeds from cached hostfile\n * base: mirror.isoc.org.il\n * epel: mirror.de. leaseweb.net\n * extras: mirror.isoc.org.il\n * updates: mirror.isoc.org.il\nExamining telnet-0.17-48.el6.x86_64.rpm: 1:telnet-0.17-48.el6.x86_64\nMarking telnet-0.17-48.el6.x86_64.rpm to be installed\nExamining screen-4.0.3-18.el6.x86_64.rpm: screen-4.0.3-18.el6.x86_64\nMarking screen-4.0.3-18.el6.x86_64.rpm to be installed\nResolving Dependencies\n--> Running transaction check\n---> Package nc.x86_64 0:1.84-24.el6 will be installed\n---> Package screen.x86_64 0:4.0.3-18.el6 will be installed\n---> Package telnet.x86_64 1:0.17-48.el6 will be installed\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package Arch Version Repository Size\n================================================================================\nInstalling:\n nc x86_64 1.84-24.el6 /nc-1.84-24.el6.x86_64 109 k\n screen x86_64 4.0.3-18.el6 /screen-4.0.3-18.el6.x86_64 795 k\n telnet x86_64 1:0.17-48.el6 /telnet-0.17-48.el6.x86_64 109 k\n\nTransaction Summary\n================================================================================\nInstall 3 Package(s)\n\nTotal size: 1.0 M\nInstalled size: 1.0 M\nDownloading Packages:\nRunning rpm_check_debug\nRunning Transaction Test\nTransaction Test Succeeded\nRunning Transaction\n\r Installing : nc-1.84-24.el6.x86_64 1/3 \n\r Installing : 1:telnet- 0.17-48.el6.x86_64 2/3 \n\r Installing : screen-4.0.3-18.el6.x86_64 3/3 \n\r Verifying : screen-4.0.3-18.el6. x86_64 1/3 \n\r Verifying : 1:telnet-0.17-48.el6.x86_64 2/3 \n\r Verifying : nc-1.84-24.el6. x86_64 3/3 \n\nInstalled:\n nc.x86_64 0:1.84-24.el6 screen.x86_64 0:4.0.3-18.el6 \n telnet.x86_64 1:0.17-48.el6 \n\nComplete!\n"]}
PLAY RECAP ********************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
任务期间启用此回购
醇>
这是我的剧本:
client.send("GET / HTTP1.1\r\nHost: www.google.com\r\n\r\n")
输出:
client.send('GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n')
答案 1 :(得分:0)
为了使用with_items
我相信它期待一个yaml列表,而不是逗号分隔列表。
name: install local packages
yum: name="/my/path/{{ item }}" state=installed
with_items:
- package1.rpm
- package2.rpm
- package3.rpm
http://docs.ansible.com/ansible/playbooks_loops.html#standard-loops