我想在“{{playbook_dir}} / files / 目录中放入一些rpm包,然后复制并安装这些包。据我所知,我可以通过使用寄存器来实现。结果变量。这是我的剧本的一部分:
- name: Copy packages
copy: src={{ item }} dest=/root/
with_fileglob:
- "{{ playbook_dir }}/files/*.rpm"
register: my_pkgs
loop_control:
label: "Copy {{ item | basename }}"
- name: Install packages
yum: name={{ item.path }} state=present
with_items: "{{ my_pkgs.results }}"
loop_control:
label: "Install {{ item.path | basename }}"
在第一次发布时我得到了
TASK [my-role : Install packages] *******************************************************
fatal: [my-host]: FAILED! => {"failed": true, "msg": "the field 'args' has \
an invalid value, which appears to include a variable that is undefined. The \
error was: 'dict object' has no attribute 'path'\n\nThe error appears to have \
been in '/root/ansible/test/roles/my-role/tasks/main.yml': line 9, column 3, but \
may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe \
offending line appears to be:\n\n\n- name: Install packages\n ^ here\n"}
但是在第二个
TASK [my-role : Install packages] *******************************************************
changed: [my-host] => (item=Install package1.rpm)
changed: [my-host] => (item=Install package2.rpm)
我不明白:我错过了什么吗?这是一个错误还是一个功能?
UPD:ansible-2.3.1.0-1
@techraf是对的:没有path
变量,但仅在第一次运行时。在第二次运行path
变量时,我会使用dest
来表示我的情况。
答案 0 :(得分:0)
您不需要在第一项任务中注册任何内容。您可以在两个任务中使用相同的循环。
- name: Copy packages
copy: src={{ item }} dest=/root/
with_fileglob:
- "{{ playbook_dir }}/files/*.rpm"
loop_control:
label: "Copy {{ item | basename }}"
- name: Install packages
yum: name=/root/{{ item | basename }} state=present
with_fileglob:
- "{{ playbook_dir }}/files/*.rpm"
loop_control:
label: "Install {{ item | basename }}"