G'day everyone, if you're currently learning Ansible and want to see how all these modules fit together to build something useful, please consider checking out my course and letting me know what you think! It's currently in "early access" while I finish off the last chapter, and the first part of the course is free so you can try it out: learn.toptechskills.com/courses/productive-with-ansible. Thanks for all your support and happy coding!
@merxvell5 жыл бұрын
literally just been looking for something like this all day ty
@toptechskills5 жыл бұрын
Thanks for the comment merxvell, I'm glad you found what you were looking for in this video.
@barakathulla88814 жыл бұрын
I have watched other videos but i didn't understand those but the way you explaining the concept is very nice an d it is very much helpfull.
@toptechskills4 жыл бұрын
Hi barakath ulla, thank you for your kind comment, I'm glad it was helpful for you. Good luck with Ansible.
@suresh16862 жыл бұрын
awesome explanation, thanks for your video. Can you please tell me this ? Does Ansible copy module do an MD5SUM or CHECKSUM before copying the file from source to destination ?
@toptechskills2 жыл бұрын
Thank you for the comment. Given the [return values](docs.ansible.com/ansible/latest/modules/copy_module.html#return-values) for the module, I would feel confident that it takes a hash _after_ running the copy, but I'm not sure if it does so _before_. The copy module does change checking, so I presume it either diffs the full content of the new and old files, or their hashes, prior to doing the copy.
@ahsan-li7sh5 жыл бұрын
Love your ansible videos, please continue
@toptechskills5 жыл бұрын
Thanks for your comment Ahsan, I'm really happy you love the Ansible videos!
@ahsan-li7sh5 жыл бұрын
@@toptechskills there are lots of ansible videos on KZbin but most of them are same contain similar content but I like your videos which are more specific. Thanks a lot for doing that.
@merlingt1 Жыл бұрын
Excellent video, thank you.
@priyeshsingh93383 жыл бұрын
It was great explanation ,can we use copy module to replace file in several containers or do we have other module can u plz tell
@toptechskills3 жыл бұрын
Can you give some more details about your setup and what you're trying to do? e.g. how are you using the containers, what are you trying to do with the files? Thank you
@vikasarora83575 жыл бұрын
Really liked ur all videos, falling short of words to thank you,will simply say “Love you and your way of explanation bro!! “
@toptechskills5 жыл бұрын
Really appreciate the kind comment, thank you 🙏
@monday67405 жыл бұрын
Interesting examples, thanks man
@angringo5 жыл бұрын
nice video, what kind of text editor do you use that has terminal included and executes the command rightaway? see you are working on a mac
@toptechskills5 жыл бұрын
Hi rootje angringo, I'm using Visual Studio Code with the Ansible extension by Microsoft. code.visualstudio.com marketplace.visualstudio.com/items?itemName=vscoss.vscode-ansible The terminal feature is super important to me, I love having it in the same screen as my code. I am manually executing the commands though, but I can do it all with my keyboard quite quickly. I bound "Cmd + Shift + m" to move focus to the terminal and then I just press up and enter to run the previous command. Thanks for watching!
@TimFord655 жыл бұрын
Great content and love the series. I have watched the shell module too! If you are collecting data from another module, written locally and you need to do some string manipulations with sed, awk, print, tr, etc., how would you string multiple shell commands together using the shell module? Is it possible to execute a script on the ansible control machine to do the file manipulation instead of running the shell module?
@toptechskills5 жыл бұрын
Hi Tim, thank you for the comment. Based on your description, it sounds like the most suitable Ansible module would be the `script` module: docs.ansible.com/ansible/latest/modules/script_module.html#script-module. This module lets you execute a script from the control host on the remote host but without needing to transfer it. Hope that helps. If not, let me know some more details about your use case and I'll try to suggest another way.
@rameshpolarapu4 жыл бұрын
Thank you, straight to the point. I have started using Ansible, with this video and your website written playbook to copy files. The link to website is not working to your website, please check. Had to search and go to your site.
@toptechskills4 жыл бұрын
Hi Ramesh Polarapu, thank you for the comment. I checked the links in the video and they all appear to be working. Can you let me know which one is broken? Thanks
@ap_in Жыл бұрын
: Thanks for the videos. I'm trying to copy a directory having files and folders with different permissions and owner with "mode: preserve" to retain the same on remote as well, but it gets changed. Could please correct me.
@toptechskills9 ай бұрын
`mode: preserve` should only preserve the mode of the original file, but the owner and group will have to change.
@hprangana3 жыл бұрын
awesome content. thanks a lot
@toptechskills3 жыл бұрын
Thanks for your kind comments Isuru 🙏
@milotamir4 жыл бұрын
Amazing content. Thank you very much
@toptechskills4 жыл бұрын
Thank you for the kind comment Tamir Milo 🙏
@karthikkrish13915 жыл бұрын
Really very interesting and very simple to understand for beginners. I keep on practicing from your videos and is very helpful guide. Thanks so much. So I have two doubts, Pls help here: 1, Is there a way we can use modules to process between two different remote hosts; (ex: copy file from remote1 to remote2) 2, Is there a way to use "loop" kind of sub-action modules in adhoc commands.
@toptechskills5 жыл бұрын
Hi Karthik Krish, thank you for your comment and kind words, I'm glad the video was helpful. I'll do my best to answer your questions. 1. In my experience I've never seen something like this, but there are definitely ways to orchestrate multiple hosts to do things together. For the example about copying a file between two remote hosts, you can do that with the `synchronize` module with the `delegate_to` keyword on the task (the docs have 2 examples to show push and pull: stackoverflow.com/questions/25505146/how-to-copy-files-between-two-nodes-using-ansible). Note that this assumes that you're able to `rsync` between the two hosts. The other way to solve this problem would be to us the control machine as a synchronization point and do it in 2 steps: 1) download the file from remote A to the control machine with `fetch`, 2) upload the file from the control machine to remote B with the `copy` module. Other tasks that require orchestration between 2 remote hosts will generally follow the same 2 patterns as the copy file example: i.e. 1) you call a command on a remote host to communicate directly with another host (usually with `delegate_to`), or 2) you use the control machine as the store of state and do it with 2 steps. If you have any other specific examples of where you want to do this sort of thing, let me know and I'll try to help. 2. I've never seen loops used outside of playbooks and Googling it returned nothing to suggest that it's possible. What's the use case? Is it not possible to create a very simple playbook? Thanks so much for the interesting questions.
@karthikkrish13915 жыл бұрын
@@toptechskills Wow thanks so much for the solution to orchestration between hosts. 1, Nice ideas. I think using the Synchronize(for transfer between remotes) and host specific tasks we can make a complete orchestration between multiple hosts in a single playbook. But I must take care of the permissions and password protection for rsync. 2, The truth is Ansible made me lazy and I never ssh manually into remotes nowadays ;-p... So for simple tasks I use a quick adhoc to orchestrate. But recently I faced constraints to use 'when' condition or 'loop' kind of sub-action modules and later we achieved it through playbooks. Just wanted to know if there is any way here.
@ilyesdjerroud70034 жыл бұрын
thank you for this video , now i'm looking to copy multiple files in a directory to a multiple destinations , is this possible ?
@toptechskills4 жыл бұрын
Hi Ilyes DJERROUD, this is definitely possible. You can use `copy` with `loop` (example at www.toptechskills.com/ansible-tutorials-courses/ansible-copy-module-tutorial-examples/#how-to-copy-multiple-files-with-a-loop) or your can do a recursive copy (example at www.toptechskills.com/ansible-tutorials-courses/ansible-copy-module-tutorial-examples/#how-to-copy-a-directory-from-the-local-host-to-a-remote-host-recursive-copy). From the docs, it mentions that the `copy` module is not efficient for copying a large number of files at the same time and that you should use the `synchronize` module (wrapper for `rsync`) in that case (Ansible docs at docs.ansible.com/ansible/latest/modules/synchronize_module.html#synchronize-module) Hope this helps, let me know if you have any problems. Thanks for your comment.
@seanxu12893 жыл бұрын
Thanks for the video. How do you define the $HOHE of the remote servers?
@toptechskills3 жыл бұрын
Hi Sean, the $HOME environment variable will usually be set by the shell when you log in. It's usually defined in the UNIX/Linux user account in /etc/passwd. With Ansible you should be able to use the `user` module (docs.ansible.com/ansible/latest/modules/user_module.html#user-module) and set the `home` parameter to the correct directory. Hope that helps, thanks for your comment.
@karni-g3 жыл бұрын
Thank you for this! Can you also help with one more example where we can merge two files into a new file ? Similar to the bundle that we create using cat command. Thanks!
@toptechskills3 жыл бұрын
Hi Kami, I think the simplest way to do this would be to use the `command` or `shell` module to do the concatenation and then either pipe it directly to the output file (pipes are only possible in the `shell` module), or register the stdout of the command and then write that to a file using the `copy` command (which has idempotence checking). For example: - name: Concatenate two files shell: cat file1 file2 > file3 or - name: Read concatenated form of files command: cat file1 file2 register: cat_result - name: Write concatenated content to file copy: dest: /path/to/file3 content: "{{ cat_result.stdout }}" The benefit of the first way is that it is extremely simple and a single command, but you don't get any idempotence (change) checking; the module will _always_ show `changed` regardless of whether `file3` is different or not. The second option is slightly more complex, but using the `copy` module to write the file gives you idempotence checking and it will only show `changed` when file3 has actually changed. You could also do things like using `slurp` to read the content of files on the remote host as variables and write the contents with `copy`. Hope that helps.
@karni-g3 жыл бұрын
@@toptechskills Thank you. This was really helpful!😊
@dridimohamed92864 жыл бұрын
so easy to use thanks
@bhupendrasinghsuri4962 жыл бұрын
Liked the content but I have a doubt. Can I copy the /etc directory recursively of my ansible controller machine to remote host $HOME? If yes, please show me the play and if not why?
@toptechskills Жыл бұрын
You can do recursive copying with `copy` when copying from the control machine to the target by specifying a directory as the `src`: docs.ansible.com/ansible/latest/modules/copy_module.html#examples > src > Local path to a file to copy to the remote server; can be absolute or relative. *If path is a directory, it is copied recursively*... This does not work with `remote_src` set to true. One note from the docs as well: > The copy module recursively copy facility does not scale to lots (>hundreds) of files. For alternative, see synchronize module, which is a wrapper around rsync.
@kunalgautam39134 жыл бұрын
Hi ,I have one .jks file to copy to remote hosts from Ansible tower ,how to do that?can I write .his content as well in content?
@toptechskills4 жыл бұрын
Hi Kunal, the `copy` module can write any type of file, it would simply use a mechanism like `scp` under the hood to move a file from the control machine to the target machine, regardless of the content.
@ZunnuAli4 жыл бұрын
Good video thanks sir god bless you
@toptechskills4 жыл бұрын
Thank you for your kind comment!
@Kanrajs5 жыл бұрын
Thank you, How to copy files/directory from remote host to another remote host?
@toptechskills5 жыл бұрын
Hi Kanagaraj S, I recently replied to another comment on this video explaining 2 ways to achieve this. Here is the link to the comment: kzbin.info/www/bejne/nnWYdaONotulaqM&lc=Ugw7s4azH8fBtHxvv1t4AaABAg.8sjLwspqDia8stdb4yfYOp Hope this helps, thanks for the comment.
@MrGameX3 жыл бұрын
Please help me, I would like to copy or move an entire folder from the ansible host to the remote host. I have to move the folder with all subdirectories how can I do that? Where can I find a playbook for this?
@toptechskills3 жыл бұрын
Both the `copy` and `synchronize` modules would be suitable for this use case. I'd start with the Ansible docs, they have excellent examples of how you might use them: - docs.ansible.com/ansible/latest/modules/copy_module.html#copy-module - docs.ansible.com/ansible/latest/modules/synchronize_module.html#synchronize-module Hope that helps, thanks for your comment
@MrGameX3 жыл бұрын
@@toptechskills Thank You for feedback. Can you please tell me how it is posibile to run a playbook only on host/node without it being configured in the inventory of ansible??
@toptechskills3 жыл бұрын
@@MrGameX you will always need an inventory for Ansible to work, but if you want to do ad-hoc things against a given host or group of hosts, you can use the `-i` or `--inventory` arguments to specify the inventory when running Ansible, e.g.: ansible-playbook --inventory "host1,host2,host3" my_playbook.yml If you want to run it against a single host, make sure that the inventory ends with a comma: ansible-playbook --inventory "host1," my_playbook.yml
@jayakishoreudayagiri2614 жыл бұрын
Hi Percy could you plese met know how to copy/move directories on remote host itself
@toptechskills4 жыл бұрын
Hi jaya kishore Udayagiri, you can use the `remote_src` argument for the `copy` module to copy files and directories on the remote host. Check out this article for more info: www.toptechskills.com/ansible-tutorials-courses/ansible-copy-module-tutorial-examples/#how-to-copy-a-file-between-directories-on-a-remote-host-with-owner-group-and-file-permissions
@jayakishoreudayagiri2614 жыл бұрын
@@toptechskills could you please do some modules of windows as well
@maiaayaaoo75 жыл бұрын
Thank you. God bless you 😇
@toptechskills5 жыл бұрын
Thank you for your kind words Vikram!
@prasannasrinivas20023 жыл бұрын
copy on sensible 2.7 for entire directory of deb files to remote host having problem... will you please give some details
@toptechskills3 жыл бұрын
I'm not sure how your directory structure is laid out, but the docs might provide some guidance about the `src` field (docs.ansible.com/ansible/latest/modules/copy_module.html#copy-module): > src > Local path to a file to copy to the remote server; 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 Rsync. Hope that helps
@nikithapoolanda62574 жыл бұрын
I want to consolidate the disk usage report from “df -h /” command and sent single email which contains all the host disk usage results. Could you please help me with this ?
@toptechskills4 жыл бұрын
Hi Nikitha, this is definitely possible. My approach would be to use the `shell` or `command` module to execute the `df` command and use the `register` argument to store the output of the command on each host. You could then use `set_fact` with `delegate_to` to accumulate the all the values from each host into a fact on `localhost`. Here are some links that should help you: - www.toptechskills.com/ansible-tutorials-courses/ansible-command-module-tutorial-examples/#how-to-capture-command-module-output - docs.ansible.com/ansible/latest/modules/set_fact_module.html - docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html#delegation - stackoverflow.com/questions/43903134/ansible-accumulate-output-across-multiple-hosts-on-task-run Hope that gets you started, good luck. Thanks for your comment.
@armanbronco2 жыл бұрын
Como tendría que configurar mis hosts si quiero copiar un directorio del host 1 al host3 sin pasar por el master. Considerando que tengo 20 hosts en el inventario.
@toptechskills Жыл бұрын
This is a difficult task to with Ansible modules directly in my experience. I think the easiest way to do this would be to call `scp` or `rsync` from the `command` or `shell` module.
@krishnap88255 жыл бұрын
Interesting. Can you plese explain about win_copy module to copy files from windows machine to linux
@toptechskills5 жыл бұрын
Hi Krishna P, from my understanding of the `win_copy` module, it's designed to copy files TO a Windows machine, not from a Windows machine. What are you trying to do? Are the Windows and Linux machines both remote hosts, or is one your control machine? If both are remote machines, you will probably need to use the `fetch` module to download the file from the Windows machine to the control machine, then the `copy` module to upload the file from the control machine to the Linux machine. Hope this helps.
@krishnap88254 жыл бұрын
@@toptechskills Thanks for your reply and let me try with fetch module
@girishkumarmuthireddy2105 жыл бұрын
Hi Could you please help me in writing ansible playbook to "compare two file that are in different servers eg: file-1 is in host-1 and file-2 is in host-2 and I need to compare those two files using ansible play book". Can you help me with that.
@toptechskills5 жыл бұрын
Hi, thanks for your question. I think the best way to do this would be to use the `fetch` module to download the files from the remote hosts to your local machine (called the "control machine" in Ansible jargon), then run some tasks on the local host to compare the files. This can be done in the same play as the previous task by using `delegate_to: localhost` and `run_once: true`, or you can create a new play that has tasks that run only on localhost. Here's some links to some more information: - My video about Ansible's fetch module: kzbin.info/www/bejne/gpKzq5SAfJ6Hpck - Ansible docs on delegation and run_once: docs.ansible.com/ansible/latest/user_guide/playbooks_delegation.html Let me know if you still can't solve the problem, I'd be happy to help further.
@rvenkatesh2k8944 жыл бұрын
Could you please tell us how to copy a file & directory to an docker container
@toptechskills4 жыл бұрын
The `copy` module should work just fine if you run Ansible against your docker container using the `docker` connection plugin: docs.ansible.com/ansible/latest/plugins/connection/docker.html You can use the `ansible_connection: docker` variable to force Ansible to use the docker connection plugin for the host. The `ansible_host` would be the name of the container (instead of the hostname or IP, like you would use for the `ssh` connection plugin). Hope that helps.
@mohammedogleh5195Ай бұрын
Thank you so mucb bro
@samrat1012 жыл бұрын
good work
@d843-l5s3 жыл бұрын
Hey. While copying a directory to remote, how to skip copy operation if this folder with all the subfolders and files already exists on remote...
@toptechskills3 жыл бұрын
This is a perfect use case for `rsync`: www.digitalocean.com/community/tutorials/how-to-use-rsync-to-sync-local-and-remote-directories > It uses an algorithm that minimizes the amount of data copied by only moving the portions of files that have changed.
@d843-l5s3 жыл бұрын
@@toptechskills wow. Thanks for the help 🤗
@toptechskills3 жыл бұрын
No problem. I forgot to mention that the Ansible `synchronize ` module is a wrapper around this tool, so if you want to do things with `rsync` from Ansible it's a convenient way. docs.ansible.com/ansible/latest/modules/synchronize_module.html#synchronize-module
@haroldosalmazan5 жыл бұрын
Nice tutorial. however I am trying to copy and execute command from ansible server into remote server windows host, and i'm getting error "No Python interpreters found for host 172.16.1.4 (tried ['/usr/bin/python', 'python3.7', 'python3.6', 'python3.5', 'python2.7', 'python2.6', '/usr/libexec/platform-python', '/usr/bin/python3', 'python']) i already tried to install python on my windows server and nothing changes when run the command. what should do you think i am missing? thank you @TopTechSkills
@toptechskills5 жыл бұрын
Hi Jarold Salmazan, I would suggest following the guide here to make sure your Windows remote is correctly set up for Ansible: docs.ansible.com/ansible/latest/user_guide/windows_setup.html. If you follow the guide and still have issues, please let me know and I'll help out further.
@sagargavli35594 жыл бұрын
How to do it if you want to copy from node to master in Ansible. Thanks in advance
@toptechskills4 жыл бұрын
Hi Sagar, you'd use the `fetch` command for that task. I wrote an article about the `fetch` module here: www.toptechskills.com/ansible-tutorials-courses/ansible-fetch-module-tutorial-examples/. Hope this helps, thanks for your comment.
@sagargavli35594 жыл бұрын
@@toptechskills Thanks It worked . I think you are one of the best person for Ansible so far I have seen.
@kasthuriarachchi4 жыл бұрын
do you have copy module intro for Linux to windows ?
@toptechskills4 жыл бұрын
Hi Suranga Kasthuriarachchi, on the docs for the `copy` module (docs.ansible.com/ansible/latest/modules/copy_module.html#copy-module) it has the advice: For Windows targets, use the win_copy module instead. The docs are available at docs.ansible.com/ansible/latest/modules/win_copy_module.html#win-copy-module.
@kasthuriarachchi4 жыл бұрын
Percy Grunwald from TopTechSkills is that connent via winrm ?
@toptechskills4 жыл бұрын
Sorry, I don't know
@ravimahajan833 жыл бұрын
I am using copy module for multiple files & directory but it will take 30 min while size is in mb
@toptechskills3 жыл бұрын
Hi Ravi, from the docs at docs.ansible.com/ansible/latest/modules/copy_module.html#copy-module: > The copy module recursively copy facility does not scale to lots (>hundreds) of files. For alternative, see synchronize module, which is a wrapper around rsync. I'd suggest using the `synchronize` module for your needs. Hope that helps
@dhir_AND2 жыл бұрын
How to copy a entire dir from remote host to localhost ?
@toptechskills2 жыл бұрын
You can do that with the "fetch" module: www.toptechskills.com/ansible-tutorials-courses/ansible-fetch-module-tutorial-examples/ Hope that helps!
@ashokkumarreddy22884 жыл бұрын
How to copy file one location to another location on same server with different users
@toptechskills4 жыл бұрын
I would first run the `copy` module as the root user (`become: true`) with `remote_src: true` to copy the file into the new location, and then use the `file` module to set the correct ownership of the file. Hope that helps!
@ashokkumarreddy22884 жыл бұрын
@@toptechskills Thanks...!!!
@namanchandra53874 жыл бұрын
How to fetch just the permissions of a file?
@toptechskills4 жыл бұрын
Hi naman chandra, I think the best way would be to use the `stat` module (docs.ansible.com/ansible/latest/modules/stat_module.html#stat-module). One of the outputs of this module is `mode` of the file. ``` - name: stat the file stat: path: /path/to/file register: stat_result - name: print the file mode debug: msg: "File mode: {{ stat_result.stat.mode }}" ``` Hope this helps, thank you for your comment!
@ankukumar-hi2jt9 ай бұрын
how we can copy someting to a file without overwriting existing contecnt
@toptechskills9 ай бұрын
The `copy` module has a `backup` parameter that will create a backup of the original file (if it changed). docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html#parameters