The template gets copied normally in /etc/nginx/sites-enabled
On running this command: ansible localhost -b -m copy -a "src=/abc/efg/ngs/templates/sites-enabled.j2 dest=/etc/nginx/sites-enabled"
The file gets copied.
:/etc/nginx/sites-enabled$ ls gives the output as default & sites-enabled.j2.
How to copy the template provided in /ngs to /etc/nginx/sites-enabled/default and how to start the nginx using adhoc the commands?
What I understood from your question is that:
You want to copy multiple template files from
src = "/abc/efg/ngs/"todest = "/etc/nginx/sites-enabled/default".You want to restart Nginx.
To achieve this using Adhoc command:
COPY FILES:
ansible localhost -b -m copy -a "src=/abc/efg/ngs/templates dest=/etc/nginx/sites-enabled/default/START NGINX USING COMMAND MODULE:
ansible localhost -m command -a "systemctl start nginx"START NGINX USING SHELL MODULE:
ansible localhost -m shell -a "systemctl start nginx"Ref to ad-hoc commands: https://docs.ansible.com/ansible/latest/user_guide/intro_adhoc.html
To achieve this using the playbook command:
Ref: https://docs.ansible.com/ansible/2.4/copy_module.html
Ref: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html
But rather I would suggest If you learn about handlers as they are very much helpful to do these kinds of tasks when you want to restart/reload any service only when a change happens.
Ref: https://docs.ansible.com/ansible/latest/user_guide/playbooks_handlers.html
If you asked something else, let me know.