An `sed` solution:
sed -nEe '/\[(prod|dev)_env]/!d;N;:loop' -e 's/.*\
//;${p;d;};N;P;/\
\[/D;bloop' hosts.yml
* `/\[(prod|dev)_env]/!d` drops all lines until `[prod_env]` or `[dev_env]` ist found
* `N;:loop` adds the next line and starts a loop
* inside the loop we remove the first of the two lines with `s/.*\
//`, because it is either the `[...env]` line or we already printed it in the last loop cycle
* `${p;d;}` prints the remaining lines if we reached the last line while printing
* `N;P` adds the next line and prints the current one
* `/\
\[/D` looks if the next line starts with a `[`. In this case the first line in the buffer (already printed) can be discarded and we start over with that `[` line
* `bloop` otherwise loop
Instead of adding the next line to the buffer, printing and removing the old one, you can go line by line, but this would require another loop, because you can't start over with `D`