Skip to content

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:

  1. 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.

  1. Navigate to the http-cats/configuration/ansible repository in GitLab
  2. Goto Settings in the left hand menu
  3. Followed by CI/CD
  4. Above five sections down there is a section called Variables - click Expand here

We'll be presented with a panel like this:

CI/CD Variables

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:

CI/CD Variables

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 Variable is fine
  • Environment scope - this can be left as is
  • Flags - we leave the Protect variable flag set to true; we cannot use Mask 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.


Last update: August 29, 2021