Does not seem so plus your whole if / then
syntax was incorrect.
The next thing you will run into is you can't just set the index name you need to look at that solution I posted there are a number of other settings you need.
Can't just do this without the template stuff i showed here
hosts: ["localhost"]
index: "test_index"
username: "elastic"
password: "password"