---
- hosts: host
become: yes
become_method: sudo
become_user: user
tasks:
- name: Create test dir
file: >
path={{ item }}
state=directory
with_items:
- ./ansibletest
- name: Create test file
file: >
path={{ item }}
state=touch
with_items:
- ./ansibletest/test.txt
- shell: echo "test" > ./ansibletest/test.txt
- shell: cat ./ansibletest/test.txt
register: out
- debug: var=out.stdout_lines
- name: Copy to WWW root
copy: >
src={{ item }}
dest=/var/www/
force=yes
owner=www-data
mode=0755
with_items:
- ./ansibletest/test.txt
- name: View ls -l /var/www
shell: ls -l /var/www/
register: out
- debug: var=out.stdout_lines
Вывод в консоли:
$ ansible-playbook ~/test.yml
PLAY [host] ******************************************************************
TASK [setup] *******************************************************************
ok: [123.123.123.123]
TASK [Create test dir] *********************************************************
ok: [123.123.123.123] => (item=./ansibletest)
TASK [Create test file] ********************************************************
changed: [123.123.123.123] => (item=./ansibletest/test.txt)
TASK [command] *****************************************************************
changed: [123.123.123.123]
TASK [command] *****************************************************************
changed: [123.123.123.123]
TASK [debug] *******************************************************************
ok: [123.123.123.123] => {
"out.stdout_lines": [
"test"
]
}
TASK [Copy to WWW root] ********************************************************
failed: [123.123.123.123] (item=./ansibletest/test.txt) => {"failed": true, "item": "./ansibletest/test.txt", "msg": "Unable to find './ansibletest/test.txt' in expected paths."}
to retry, use: --limit @/home/user/test.retry
PLAY RECAP *********************************************************************
123.123.123.123 : ok=6 changed=3 unreachable=0 failed=1
Во-первых: нет запроса sudo привилегий (а должен быть?).
Во-вторых:
"Unable to find './ansibletest/test.txt' in expected paths."
Я это ЕБ@@ЕЕ сообщение не могу 3 часа победить... Как я только пути не прописывал - не работает...