Ansible Copy Module Tutorial - Complete Beginner's Guide

Поделиться
HTML-код
  • Опубликовано: 1 июл 2024
  • 🎓 My new Ansible Course (Productive with Ansible, 2024) now in Early Access: learn.toptechskills.com/cours...
    In this tutorial video I give you a complete beginner's guide to the super useful Ansible Copy Module. You can use the Ansible Copy Module to copy files from your local host to a remote host, copy files between locations on the remote host, as well as put text content directly into a file from a task. I cover all these functions in the video and I've split this video into sections to make it easier to navigate:
    - 0:39 -- 1a. Copy a Single File (from local host to remote host)
    - 1:59 -- 1b. Copy Multiple Files (from local host to remote host)
    - 3:14 -- 1c. Copy Directories (from local host to remote host)
    - 5:56 -- 2. Set File Ownership & Permissions (for the copied file(s))
    - 7:13 -- 3. Copy on a Remote Host (copy files between locations on a remote host)
    - 8:26 -- 4. Write Text to a File (directly from the playbook)
    ✅ SEE HOW I SET UP ANSIBLE == • My Ansible Setup for T...
    ℹ️ READ THE IN-DEPTH TUTORIAL HERE == bit.ly/2FzWlGt
    Thanks for watching and hope it's entertaining/useful for you! Hit me up in the comments if you have any questions or feedback 💪.
    Related & Channel
    ▶️ bit.ly/2VWid3D == Playlist of all Ansible videos
    ⭐️ bit.ly/2HavqCu == Subscribe to our RUclips Channel
    Our Site & Socials
    🌐 bit.ly/2shtKwZ == TopTechSkills.com
    🐦 bit.ly/2RkgZkk == @TopTechSkills on Twitter
    🐦 bit.ly/2AA19aN == @PercyGrunwald on Twitter
    😃 bit.ly/2ACQgEW == @TopTechSkills on Facebook
    🕹 bit.ly/2CWR3ST == @PercyGrunwald on Twitch
  • НаукаНаука

Комментарии • 94

  • @toptechskills
    @toptechskills  Месяц назад

    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!

  • @monday6740
    @monday6740 5 лет назад +3

    Interesting examples, thanks man

  • @merxvell
    @merxvell 5 лет назад +2

    literally just been looking for something like this all day ty

    • @toptechskills
      @toptechskills  5 лет назад

      Thanks for the comment merxvell, I'm glad you found what you were looking for in this video.

  • @merlingt1
    @merlingt1 Год назад +1

    Excellent video, thank you.

  • @vikasarora8357
    @vikasarora8357 4 года назад +1

    Really liked ur all videos, falling short of words to thank you,will simply say “Love you and your way of explanation bro!! “

    • @toptechskills
      @toptechskills  4 года назад

      Really appreciate the kind comment, thank you 🙏

  • @dridimohamed9286
    @dridimohamed9286 4 года назад +1

    so easy to use thanks

  • @ahsan-li7sh
    @ahsan-li7sh 5 лет назад +1

    Love your ansible videos, please continue

    • @toptechskills
      @toptechskills  5 лет назад

      Thanks for your comment Ahsan, I'm really happy you love the Ansible videos!

    • @ahsan-li7sh
      @ahsan-li7sh 5 лет назад +1

      @@toptechskills there are lots of ansible videos on RUclips but most of them are same contain similar content but I like your videos which are more specific. Thanks a lot for doing that.

  • @barakathulla8881
    @barakathulla8881 4 года назад +1

    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.

    • @toptechskills
      @toptechskills  4 года назад

      Hi barakath ulla, thank you for your kind comment, I'm glad it was helpful for you. Good luck with Ansible.

  • @milotamir
    @milotamir 4 года назад +1

    Amazing content. Thank you very much

    • @toptechskills
      @toptechskills  4 года назад

      Thank you for the kind comment Tamir Milo 🙏

  • @maiaayaaoo7
    @maiaayaaoo7 5 лет назад +1

    Thank you. God bless you 😇

  • @samrat101
    @samrat101 2 года назад +1

    good work

  • @hprangana
    @hprangana 2 года назад +1

    awesome content. thanks a lot

    • @toptechskills
      @toptechskills  2 года назад

      Thanks for your kind comments Isuru 🙏

  • @ZunnuAli
    @ZunnuAli 4 года назад +1

    Good video thanks sir god bless you

  • @TimFord65
    @TimFord65 5 лет назад +1

    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?

    • @toptechskills
      @toptechskills  5 лет назад

      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.

  • @suresh1686
    @suresh1686 2 года назад +1

    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 ?

    • @toptechskills
      @toptechskills  2 года назад +1

      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.

  • @angringo
    @angringo 5 лет назад +2

    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

    • @toptechskills
      @toptechskills  5 лет назад +2

      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!

  • @priyeshsingh9338
    @priyeshsingh9338 2 года назад +1

    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

    • @toptechskills
      @toptechskills  2 года назад

      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

  • @rameshpolarapu
    @rameshpolarapu 4 года назад +1

    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.

    • @toptechskills
      @toptechskills  4 года назад

      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

  • @karthikkrish1391
    @karthikkrish1391 5 лет назад +1

    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.

    • @toptechskills
      @toptechskills  5 лет назад +2

      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.

    • @karthikkrish1391
      @karthikkrish1391 5 лет назад +1

      @@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.

  • @Kanrajs
    @Kanrajs 5 лет назад +1

    Thank you, How to copy files/directory from remote host to another remote host?

    • @toptechskills
      @toptechskills  5 лет назад

      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: ruclips.net/video/hD5DpWmvr4A/видео.html&lc=Ugw7s4azH8fBtHxvv1t4AaABAg.8sjLwspqDia8stdb4yfYOp
      Hope this helps, thanks for the comment.

  • @ilyesdjerroud7003
    @ilyesdjerroud7003 4 года назад +1

    thank you for this video , now i'm looking to copy multiple files in a directory to a multiple destinations , is this possible ?

    • @toptechskills
      @toptechskills  4 года назад

      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.

  • @karni-g
    @karni-g 3 года назад +1

    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!

    • @toptechskills
      @toptechskills  3 года назад +1

      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-g
      @karni-g 3 года назад +1

      @@toptechskills Thank you. This was really helpful!😊

  • @ap_in
    @ap_in Год назад +1

    : 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.

    • @toptechskills
      @toptechskills  5 месяцев назад

      `mode: preserve` should only preserve the mode of the original file, but the owner and group will have to change.

  • @seanxu1289
    @seanxu1289 3 года назад +1

    Thanks for the video. How do you define the $HOHE of the remote servers?

    • @toptechskills
      @toptechskills  3 года назад

      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.

  • @kunalgautam3913
    @kunalgautam3913 3 года назад +1

    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?

    • @toptechskills
      @toptechskills  3 года назад

      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.

  • @prasannasrinivas2002
    @prasannasrinivas2002 3 года назад +1

    copy on sensible 2.7 for entire directory of deb files to remote host having problem... will you please give some details

    • @toptechskills
      @toptechskills  3 года назад

      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

  • @krishnap8825
    @krishnap8825 4 года назад +1

    Interesting.
    Can you plese explain about win_copy module to copy files from windows machine to linux

    • @toptechskills
      @toptechskills  4 года назад

      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.

    • @krishnap8825
      @krishnap8825 4 года назад +1

      @@toptechskills Thanks for your reply and let me try with fetch module

  • @girishkumarmuthireddy210
    @girishkumarmuthireddy210 4 года назад +1

    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.

    • @toptechskills
      @toptechskills  4 года назад

      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: ruclips.net/video/LaPzaJG9Tog/видео.html
      - 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.

  • @nikithapoolanda6257
    @nikithapoolanda6257 3 года назад +1

    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 ?

    • @toptechskills
      @toptechskills  3 года назад

      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.

  • @bhupendrasinghsuri496
    @bhupendrasinghsuri496 Год назад +1

    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
      @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.

  • @rvenkatesh2k894
    @rvenkatesh2k894 4 года назад +1

    Could you please tell us how to copy a file & directory to an docker container

    • @toptechskills
      @toptechskills  4 года назад

      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.

  • @jayakishoreudayagiri261
    @jayakishoreudayagiri261 4 года назад +1

    Hi Percy could you plese met know how to copy/move directories on remote host itself

    • @toptechskills
      @toptechskills  4 года назад +1

      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

    • @jayakishoreudayagiri261
      @jayakishoreudayagiri261 4 года назад

      @@toptechskills could you please do some modules of windows as well

  • @armanbronco
    @armanbronco Год назад +1

    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
      @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.

  • @MrGameX
    @MrGameX 3 года назад +1

    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?

    • @toptechskills
      @toptechskills  3 года назад +1

      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

    • @MrGameX
      @MrGameX 3 года назад +1

      @@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??

    • @toptechskills
      @toptechskills  3 года назад

      @@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

  • @user-by3jo8zw4p
    @user-by3jo8zw4p 3 года назад +1

    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...

    • @toptechskills
      @toptechskills  3 года назад +1

      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.

    • @user-by3jo8zw4p
      @user-by3jo8zw4p 3 года назад +1

      @@toptechskills wow. Thanks for the help 🤗

    • @toptechskills
      @toptechskills  3 года назад

      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

  • @sagargavli3559
    @sagargavli3559 3 года назад +1

    How to do it if you want to copy from node to master in Ansible. Thanks in advance

    • @toptechskills
      @toptechskills  3 года назад

      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.

    • @sagargavli3559
      @sagargavli3559 3 года назад +1

      @@toptechskills Thanks It worked . I think you are one of the best person for Ansible so far I have seen.

  • @haroldosalmazan
    @haroldosalmazan 4 года назад +1

    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

    • @toptechskills
      @toptechskills  4 года назад

      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.

  • @kasthuriarachchi
    @kasthuriarachchi 3 года назад +1

    do you have copy module intro for Linux to windows ?

    • @toptechskills
      @toptechskills  3 года назад +1

      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.

    • @kasthuriarachchi
      @kasthuriarachchi 3 года назад

      Percy Grunwald from TopTechSkills is that connent via winrm ?

    • @toptechskills
      @toptechskills  3 года назад

      Sorry, I don't know

  • @ravimahajan83
    @ravimahajan83 3 года назад +1

    I am using copy module for multiple files & directory but it will take 30 min while size is in mb

    • @toptechskills
      @toptechskills  3 года назад

      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_AND
    @dhir_AND 2 года назад +1

    How to copy a entire dir from remote host to localhost ?

    • @toptechskills
      @toptechskills  2 года назад

      You can do that with the "fetch" module: www.toptechskills.com/ansible-tutorials-courses/ansible-fetch-module-tutorial-examples/
      Hope that helps!

  • @ashokkumarreddy2288
    @ashokkumarreddy2288 4 года назад +1

    How to copy file one location to another location on same server with different users

    • @toptechskills
      @toptechskills  4 года назад +1

      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!

    • @ashokkumarreddy2288
      @ashokkumarreddy2288 4 года назад

      @@toptechskills Thanks...!!!

  • @ankukumar-hi2jt
    @ankukumar-hi2jt 5 месяцев назад

    how we can copy someting to a file without overwriting existing contecnt

    • @toptechskills
      @toptechskills  5 месяцев назад

      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

  • @namanchandra5387
    @namanchandra5387 4 года назад +1

    How to fetch just the permissions of a file?

    • @toptechskills
      @toptechskills  4 года назад

      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!