Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
blog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
blog
Commits
a588aff7
Commit
a588aff7
authored
4 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
Entry on getting an output from the GitLab Terrafrom remote state with
Ansible.
parent
f93a1d8b
No related branches found
No related tags found
No related merge requests found
Pipeline
#1397
passed
4 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
content/gitlab-tf-state-ansible.rst
+48
-0
48 additions, 0 deletions
content/gitlab-tf-state-ansible.rst
with
48 additions
and
0 deletions
content/gitlab-tf-state-ansible.rst
0 → 100644
+
48
−
0
View file @
a588aff7
Accessing the GitLab remote Terraform state from Ansible
========================================================
:date: 2021-05-08
:summary: Accessing the GitLab remote Terraform state from Ansible.
Note to self: How to get the outputs from a GitLab remote Terrafrom state from
Ansible.
.. code:: yaml
---
- name: Get Terraform outputs from the GitLab remote state
hosts:
- localhost
connection: local
become: false
gather_facts: false
vars:
project_name: amilive
tf_workspace: "{{ lookup('env', 'TF_WORKSPACE')|default('default', true) }}"
gitlab_token: "{{ lookup('env', 'GITLAB_TOKEN') }}"
gitlab_base_url: "{{ lookup('env', 'GITLAB_BASE_URL') }}"
tasks:
- name: Projects
ansible.builtin.uri:
headers:
PRIVATE-TOKEN: "{{ gitlab_token }}"
method: GET
url: "{{ gitlab_base_url }}/projects"
register: projects
- name: Request
ansible.builtin.uri:
headers:
PRIVATE-TOKEN: "{{ gitlab_token }}"
method: GET
return_content: true
status_code: [200]
url: "{{ gitlab_base_url }}/projects/{{ project_id }}/terraform/state/{{ tf_workspace }}"
vars:
project_id: "{{ (projects.json|selectattr('path', 'equalto', project_name))[0].id }}"
register: tf_state
- name: Env output
debug:
var: (tf_state.content|from_json)["outputs"]["env"]["value"]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment