I'd like to implement a service to dinamically ban an IP.
The easiest way I can think to achieve my goal is with a shell_command that would add an entry to /config/ip_bans.yaml:
shell_command:
ban_ip: "echo '- ip_address: {{ ip_address }}' >> /config/ip_bans.yaml"
If I try to invoke the service:
action: shell_command.ban_ip
data:
ip_address: "test"
it seems to work:
stdout: "- ip_address: test >> /config/ip_bans.yaml"
stderr: ""
returncode: 0
but no "test" entry is actually added to /config/ip_bans.yaml as the piping seems to be interpreted as plain text.
How may I implement this service? Are there alternative ways to achieve the desired result?
Thanks for your time.