cancel
Showing results for 
Search instead for 
Did you mean: 
spurs
Flight Engineer
Flight Engineer
  • 1,082 Views

tralining slash question

Jump to solution

Write a playbook that uses the role, called use-vhost-role.yml. Include a task to copy the HTML content from files/html/. Use the copy module and include a trailing slash after the source directory name. It should have the following content:

---
- name: Use myvhost role playbook
  hosts: webservers
  pre_tasks:
    - name: pre_tasks message
      debug:
        msg: 'Ensure web server configuration.'

  roles:
    - myvhost

  post_tasks:
    - name: HTML content is installed
      copy:
        src: files/html/
        dest: "/var/www/vhosts/{{ ansible_hostname }}"

    - name: post_tasks message
      debug:
        msg: 'Web server is configured.'








In this case,
if post_tasks, src was files/html/index.html
Will it work identically with above code?

 

Labels (1)
1 Solution

Accepted Solutions
morbius
Flight Engineer
Flight Engineer
  • 1,054 Views

From the documentation of the ansible.builtin.copy module, parameter "src":

Local path to a file to copy to the remote server.

This can be absolute or relative.

If path is a directory, it is copied recursively. In this case, if path ends with “/”, only inside contents of that directory are copied to destination. Otherwise, if it does not end with “/”, the directory itself with all contents is copied. This behavior is similar to the rsync command line tool.

 

You need to hit the documentation and practice a lot in the lab in order to be truly ready for the exam.You got a long way to go.

View solution in original post

3 Replies
morbius
Flight Engineer
Flight Engineer
  • 1,055 Views

From the documentation of the ansible.builtin.copy module, parameter "src":

Local path to a file to copy to the remote server.

This can be absolute or relative.

If path is a directory, it is copied recursively. In this case, if path ends with “/”, only inside contents of that directory are copied to destination. Otherwise, if it does not end with “/”, the directory itself with all contents is copied. This behavior is similar to the rsync command line tool.

 

You need to hit the documentation and practice a lot in the lab in order to be truly ready for the exam.You got a long way to go.

spurs
Flight Engineer
Flight Engineer
  • 995 Views
Hey thanks for the reply.
I just tried copying /etc/ and /etc to my test folder and both (with /, without/) path copied whole /etc/ directory and files. It was different to your explanation. Does it work only in playbook copy module?
spurs
Flight Engineer
Flight Engineer
  • 984 Views

Hey, I tried it by using playbook

and simply

src: /etc/ (copy only contents)

src: /etc (copy the directory and its contents)

Thanks a lot!

Join the discussion
You must log in to join this conversation.