You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/cloudflare-one/connections/connect-networks/deployment-guides/ansible.mdx
+77-92Lines changed: 77 additions & 92 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ Ansible works alongside Terraform to streamline the Cloudflare Tunnel setup proc
16
16
To complete the steps in this guide, you will need:
17
17
18
18
-[A Google Cloud Project](https://cloud.google.com/resource-manager/docs/creating-managing-projects#creating_a_project) and [GCP CLI installed and authenticated](https://cloud.google.com/sdk/docs/install).
19
-
-[Basic knowledge of Terraform](/cloudflare-one/connections/connect-networks/deployment-guides/terraform/) and[Terraform installed](https://developer.hashicorp.com/terraform/tutorials/certification-associate-tutorials/install-cli).
19
+
-[Basic knowledge of Terraform](/cloudflare-one/connections/connect-networks/deployment-guides/terraform/) and[Terraform installed](https://developer.hashicorp.com/terraform/tutorials/certification-associate-tutorials/install-cli).
20
20
-[A zone on Cloudflare](/fundamentals/setup/manage-domains/add-site/).
21
21
-[A Cloudflare API token](/fundamentals/api/get-started/create-token/) with `Cloudflare Tunnel` and `DNS` permissions.
22
22
@@ -74,32 +74,7 @@ You will need to declare the [providers](https://registry.terraform.io/browse/pr
74
74
75
75
2. Add the following providers to `providers.tf`. The `random` provider is used to generate a tunnel secret.
76
76
77
-
```txt
78
-
terraform {
79
-
required_providers {
80
-
cloudflare = {
81
-
source = "cloudflare/cloudflare"
82
-
}
83
-
google = {
84
-
source = "hashicorp/google"
85
-
}
86
-
random = {
87
-
source = "hashicorp/random"
88
-
}
89
-
}
90
-
required_version = ">= 0.13"
91
-
}
92
-
93
-
# Providers
94
-
provider "cloudflare" {
95
-
api_token = var.cloudflare_token
96
-
}
97
-
provider "google" {
98
-
project = var.gcp_project_id
99
-
}
100
-
provider "random" {
101
-
}
102
-
```
77
+
<Renderfile="terraform/providers-v5" />
103
78
104
79
### Configure Cloudflare resources
105
80
@@ -113,30 +88,53 @@ The following configuration will modify settings in your Cloudflare account.
113
88
114
89
2. Add the following resources to `Cloudflare-config.tf`:
115
90
116
-
```txt
117
-
# Generates a 64-character secret for the tunnel.
118
-
# Using `random_password` means the result is treated as sensitive and, thus,
119
-
# not displayed in console output. Refer to: https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password
120
-
resource "random_password" "tunnel_secret" {
121
-
length = 64
122
-
}
123
-
124
-
# Creates a new locally-managed tunnel for the GCP VM.
@@ -209,7 +207,7 @@ The following configuration defines the specifications for the GCP virtual machi
209
207
210
208
### Export variables to Ansible
211
209
212
-
The following Terraform resource exports the tunnel ID and other variables to `tf_ansible_vars_file.yml`. Ansible will use this data to configure and run `cloudflared` on the server.
210
+
The following Terraform resource exports the [tunnel token](/cloudflare-one/connections/connect-networks/configure-tunnels/remote-tunnel-permissions/) and other variables to `tf_ansible_vars_file.yml`. Ansible will use the tunnel token to configure and run `cloudflared` on the server.
213
211
214
212
1. In your configuration directory, create a new `tf` file:
215
213
@@ -219,20 +217,18 @@ The following Terraform resource exports the tunnel ID and other variables to `t
219
217
220
218
2. Copy and paste the following content into `export.tf`:
221
219
222
-
```txt
223
-
resource "local_file" "tf_ansible_vars_file" {
224
-
content = <<-DOC
225
-
# Ansible vars_file containing variable values from Terraform.
- name: Create the config file for cloudflared and define the ingress rules for the tunnel.
265
-
copy:
266
-
dest: "/etc/cloudflared/config.yml"
267
-
content: |
268
-
tunnel: "{{ tunnel_id }}"
269
-
credentials-file: /etc/cloudflared/cert.json
270
-
logfile: /var/log/cloudflared.log
271
-
loglevel: info
272
-
ingress:
273
-
- hostname: "ssh_app.{{ zone }}"
274
-
service: ssh://localhost:22
275
-
- service: http_status:404
276
-
- name: Create the tunnel credentials file for cloudflared.
277
-
copy:
278
-
dest: "/etc/cloudflared/cert.json"
279
-
content: |
280
-
{
281
-
"AccountTag" : "{{ account | quote }}",
282
-
"TunnelID" : "{{ tunnel_id | quote }}",
283
-
"TunnelName" : "{{ tunnel_name | quote }}",
284
-
"TunnelSecret" : "{{ secret | quote }}"
285
-
}
286
258
- name: Install the tunnel as a systemd service.
287
-
shell: cloudflared service install
259
+
shell: "cloudflared service install {{ tunnel_token }}"
288
260
- name: Start the tunnel.
289
261
systemd:
290
262
name: cloudflared
291
263
state: started
292
264
enabled: true
293
265
masked: no
266
+
- name: Deploy an example Apache web server on port 80.
267
+
shell: apt update && apt -y install apache2
268
+
- name: Edit the default Apache index file.
269
+
copy:
270
+
dest: /var/www/html/index.html
271
+
content: |
272
+
<!DOCTYPE html>
273
+
<html>
274
+
<body>
275
+
<h1>Hello Cloudflare!</h1>
276
+
<p>This page was created for a Cloudflare demo.</p>
277
+
</body>
278
+
</html>
294
279
```
295
280
296
281
[Keywords](https://docs.ansible.com/ansible/latest/reference_appendices/playbooks_keywords.html#play) define how Ansible will execute the configuration. In the example above, the `vars_files` keyword specifies where variable definitions are stored, and the `tasks` keyword specifies the actions Ansible will perform.
@@ -323,4 +308,4 @@ It may take several minutes for the GCP instance and tunnel to come online. You
323
308
324
309
## 7. Test the connection
325
310
326
-
You can now SSH to the GCP server through the new `ssh_app.<zone>` hostname. For instructions on how to connect, refer to our [SSH guide](/cloudflare-one/connections/connect-networks/use-cases/ssh/).
311
+
To test, open a browser and go to `http://http_app.<CLOUDFLARE_ZONE>.com` (for example, `http_app.example.com`). You should see the **Hello Cloudflare!** test page.
0 commit comments