CI Variables¶
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.
Note
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.
SSH Key¶
We're going to need a single variable for the Ansible pipeline:
PRIVATE_KEY
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/ansible
repository in GitLab - Goto
Settings
in the left hand menu - Followed by
CI/CD
- Above five sections down there is a section called
Variables
- clickExpand
here
We'll be presented with a panel like this:
Note
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 environmentValue
- this is the contents of the private key file, just copy and pasted inType
- the typeVariable
is fineEnvironment scope
- this can be left as isFlags
- we leave theProtect variable
flag set to true; we cannot useMask variable
for this value as it's too complex
Note
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.
Next¶
Because we're defined our CI pipeline configuration (.gitlab-ci.yml
) and the CI variables we need, we can now trigger the pipeline manually.