How to automate initial server configuration?
What you are trying to accomplish is referred to as infrastructure as code.
Which tools you select will depend on where you are operating, and what your business needs are.  If you are operating in AWS exclusively, you can skip 3rd party solutions and focus on their CloudFormation service.  Terraform (infrastructure) and Ansible (configuration) are popular cloud agnostic tools if you are operating On-Prem or across multiple cloud providers.