Before we run our Ansible pipeline we need to define a single CI variable to hold the SSH private key we want Ansible to use when connecting to our hosts.
Again: this isn't the best way of handling this problem but that's the point at this point in the book. We're showing you how-to get the job done but later on we show you how-to get the job done better and evolve your understanding of building systems that get more and more complex.
We're going to need a single variable for the Ansible pipeline:
This is the SSH private key needed to SSH into our EC2 instances and provision them.
This is the private key from the key pair we created in section
2.5 ("AWS Key Pair"). Copy and paste the contents into the variable directly. Nothing else is needed (newlines and such are preserved.)
To create this CI variable and have it be made available permanently to every CI pipeline, we have to use the main settings panel.
- Navigate to the
http-cats/configuration/ansiblerepository in GitLab
Settingsin the left hand menu
- Followed by
- Above five sections down there is a section called
We'll be presented with a panel like this:
As you can see I already have the variable defined. You need to define this so keep following along.
We'll need to click
Add variable and then follow the prompts:
We need to fill in the fields as such:
Key- the variable's name, as it will be see in the environment
Value- this is the contents of the private key file, just copy and pasted in
Type- the type
Environment scope- this can be left as is
Flags- we leave the
Protect variableflag set to true; we cannot use
Mask variablefor this value as it's too complex
With a bit of extra work we could make
Mask variable available to us, but for now we'll keep things simple.
Now just click
Add variable and you're done.
Because we're defined our CI pipeline configuration (
.gitlab-ci.yml) and the CI variables we need, we can now trigger the pipeline manually.