Deploying docker swarm using bash script without docker-machine

Running Ubuntu 18.04 on virtualmachines and want to install and deploy docker swarm “automatically” using bash script. (Almost like a one-click installation)
Reffering to : Deploying docker swarm without using docker machine

Question: How can I make this possible? Take bunch of manually commands and feed it into a bash script? How do I connect these VMs together in this swarm?

Source: StackOverflow