Answer the question
In order to leave comments, you need to log in
Ansible problems writing first playbook?
---
- 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
"Unable to find './ansibletest/test.txt' in expected paths."
Answer the question
In order to leave comments, you need to log in
And what do you want to achieve? Here are the playbooks for the webserver, if you're interested.
The copy module copies from the local machine to a remote machine.
And just out of curiosity - why are you adding ./ to an already relative path?
your file must be located locally in the recipe folder and not on a remote server
To crawl by the contents of files, use with_file
offtop, it is better to use the "native" syntax for yaml:
- name: Create test dir
file:
path: "{{ item }}"
state: directory
with_items:
- ./ansibletest
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question