Using a piece of documentation in order to write your own program does not generally produce a derivative work. A derivative work would mean that you copied or transformed copyrightable portions of the source material in a manner that would require permission. Keep in mind that copyright only protects the particular expression of an idea. The idea itself is not copyrightable. So let's take a look at your example. Suppose this example appears in the documentation:
- name: Put in the dog photo
The idea of this is "a script to copy a file." Anyone is free to write his own script that copies a file. No one can own that idea. Additionally, elements which are strictly necessary to do this are not protected by copyright, so let's remove the elements which are not strictly necessary:
- name: A
Where the elements A, B, C, D and E are generic symbols which represent parts of the document which are not strictly necessary. Whether the text in those elements themselves are creative enough to be copyrightable or whether your use of them would be infringing is another question, though. For example, in my opinion, the text in A "Put in the dog photo" is so short and generic that it is very plausible that two independent authors, each having her own idea in mind about putting in a photo of a dog somewhere, decided to write precisely the same words "put in the dog photo" independently. That doesn't mean those two authors are copying from each other and it doesn't mean one of them would require permission from the other in order to use the same words. However, if the text in A were something substantial, original, and creative, then the particular text in A could be copyrightable and using it or something derived from it would require permission.
In this case, though, I think you are not interested in copying A, B, C, D and E. You are interested in the other words of the document. However, if you look at those portions, they should be ignored when analyzing the copyright. Those elements ("name:", "copy:" etc.) are necessary for writing the script. They are part of the language used by the program. In other words, there is not really any other way to write a script that copies a document, other than to use those specific keywords. In copyright these are called scènes à faire. I.e. they are parts of a type of work that are basically obligatory.
Using the ansible example, I deliberately copy out of the ansible documentation all the time, ... [and] I would paste it right into my editor ...
I believe you are talking about using the copy/paste function of your computer. Copyright is not generally concerned with the method that you used to do the copying. For example, if you copy a chapter of a book, it does not generally matter whether you used a photocopier, whether you clicked copy/paste in your computer, whether you clicked "Forward" in your e-mail client (which also makes a copy), or whether you wrote it out by hand on a piece of paper. A copy is a copy.
On the flip side, using copy/paste of the non-copyrightable parts is not "copying" in the sense that copyright is talking about. It sounds like you are using copy/paste simply as a convenient way to avoid typing or to avoid making typos. In other words you could have just as well used copy/paste on this:
- name: A
Which as we've already established has no copyrightable elements left in it, so it's not possible to infringe anyone's copyright by producing this, no matter what method you used to produce it.