Is it possible to configure ssl on demand for all domains from caddyfile and also cloudfare dns for one domain from caddyfile as well.
If not, can I use caddyfile for configuring domain and servers and json just for aal on demand and cloudfare, can caddy2 work with both config adapters?
I think what you’ll want to do is create two different policies (see JSON Config Structure - Caddy Documentation), one with the domain you want to enable the DNS challenge for (setting "host" to ["yourdomain.com"] to only enable it for that domain), and the other with on_demand enabled (and with "host" being empty, which I think is catch-all but I’m not 100% certain here, @matt could clarify).
So the way Caddy deals with config internally is entirely using JSON. So what you could do is load an initial Caddyfile config, then use the admin API to push any modifications you wish to make after running it. Or, you can just use caddy adapt to get the underlying JSON representation the Caddyfile would map to, then make your modifications to that (you could script it with jq for example).
$ caddy validate --config ~/Desktop/caddy_dejan.json
2020/03/17 16:35:40.650 INFO using provided configuration {"config_file": "/Users/matt/Desktop/caddy_dejan.json", "config_adapter": ""}
2020/03/17 10:35:40 [INFO][cache:0xc0005925f0] Started certificate maintenance routine
2020/03/17 16:35:40.652 INFO http server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS {"server_name": "srv0", "https_port": 443}
2020/03/17 16:35:40.652 WARN http most clients do not trust second-level wildcard certificates (*.tld) {"domain": "*.*"}
2020/03/17 16:35:40.652 INFO http enabling automatic HTTP->HTTPS redirects {"server_name": "srv0"}
2020/03/17 10:35:40 [INFO][cache:0xc0005925f0] Stopped certificate maintenance routine
Valid configuration