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?
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.
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.
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!
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.