If want automate installation and configuration of Keycloak, You can instead use admin-cli
you can create realm role something like this
$ kcadm.sh create roles -r demorealm ...