There are of some downsides to that approach which stem from the fact that you can’t possibly declare every possible thing. For instance, if you were to run the above declaration and then later remove the declaration, chef wouldn’t know to delete the directory; at that point chef wouldn’t know anything about the directory at all. So ideally you can build infrastructure from scratch each time (Docker, etc) rather than having to converge an existing machine.
How to write idempotent Bash scripts
11–20 of 195 posts
Re: How to write idempotent Bash scripts
#12It’s good to know which command line tools are idempotent, but I think once you start running automated scripts repeatedly you’re better off with something like Chef where you declaratively define the end state and let chef figure out how to converge upon that state. Taking the “create a directory” example, you would say “I want to end up in a state where this directory is created and has these permissions” and chef…
Re: How to write idempotent Bash scripts
#13Re: How to write idempotent Bash scripts
#14Every call to touch will alter the modification time of the file (example.txt in this case).
Re: How to write idempotent Bash scripts
#15Re: How to write idempotent Bash scripts
#16Re: How to write idempotent Bash scripts
#17Why wouldn’t you use make? Side-effect tracking and cleanup is the job of a build tool.
Re: How to write idempotent Bash scripts
#18> This is an easy one. Touch is by default idempotent. This means you can call it multiple times without any issues. A second call won’t have any effects Every call to touch will alter the modification time of the file (example.txt in this case).
It is very difficult to write truly idempotent bash scripts (consider log files). Creating sort of idempotent or at least rerunnable scripts would be nice but I think even that would take more care than this.
Re: How to write idempotent Bash scripts
#19Many people who write scripts do not factor the environment they are run in and miss including traps to handle events like being terminated mid-way thru and cleaning up to a sanitized state. After all, creating a file, you can't presume their is enough free space, but people do in scripts all the time. Then you have scripts that you want run once and if run again not have any more effect. FOr example a script to be r…