Skip to content

Commit 62dfaa7

Browse files
committed
update ansible example
1 parent c918337 commit 62dfaa7

File tree

1 file changed

+18
-72
lines changed
  • src/content/docs/cloudflare-one/connections/connect-networks/deployment-guides

1 file changed

+18
-72
lines changed

src/content/docs/cloudflare-one/connections/connect-networks/deployment-guides/ansible.mdx

Lines changed: 18 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Ansible works alongside Terraform to streamline the Cloudflare Tunnel setup proc
1616
To complete the steps in this guide, you will need:
1717

1818
- [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).
2020
- [A zone on Cloudflare](/fundamentals/setup/manage-domains/add-site/).
2121
- [A Cloudflare API token](/fundamentals/api/get-started/create-token/) with `Cloudflare Tunnel` and `DNS` permissions.
2222

@@ -134,47 +134,6 @@ The following configuration will modify settings in your Cloudflare account.
134134
]
135135
}
136136
}
137-
138-
# (Optional) Routes internal IP of GCP instance through the tunnel for private network access using WARP.
139-
resource "cloudflare_zero_trust_tunnel_cloudflared_route" "example_tunnel_route" {
140-
account_id = var.cloudflare_account_id
141-
tunnel_id = cloudflare_zero_trust_tunnel_cloudflared.gcp_tunnel.id
142-
network = google_compute_instance.http_server.network_interface.0.network_ip
143-
comment = "Example tunnel route"
144-
}
145-
146-
# Creates a reusable Access policy.
147-
resource "cloudflare_zero_trust_access_policy" "allow_emails" {
148-
account_id = var.cloudflare_account_id
149-
name = "Allow email addresses"
150-
decision = "allow"
151-
include = [
152-
{
153-
email = {
154-
email = var.cloudflare_email
155-
}
156-
},
157-
{
158-
email_domain = {
159-
domain = "@example.com"
160-
}
161-
}
162-
]
163-
}
164-
165-
# Creates an Access application to control who can connect to the public hostname.
166-
resource "cloudflare_zero_trust_access_application" "http_app" {
167-
account_id = var.cloudflare_account_id
168-
type = "self_hosted"
169-
name = "Access application for http_app.${var.cloudflare_zone}"
170-
domain = "http_app.${var.cloudflare_zone}"
171-
policies = [
172-
{
173-
id = cloudflare_zero_trust_access_policy.allow_emails.id
174-
precedence = 1
175-
}
176-
]
177-
}
178137
```
179138

180139
### Configure GCP resources
@@ -197,7 +156,7 @@ The following configuration defines the specifications for the GCP virtual machi
197156
}
198157
199158
# Sets up a GCP VM instance.
200-
resource "google_compute_instance" "origin" {
159+
resource "google_compute_instance" "http_server" {
201160
name = "ansible-inst"
202161
machine_type = var.machine_type
203162
zone = var.zone
@@ -248,7 +207,7 @@ The following configuration defines the specifications for the GCP virtual machi
248207

249208
### Export variables to Ansible
250209

251-
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.
252211

253212
1. In your configuration directory, create a new `tf` file:
254213

@@ -263,10 +222,8 @@ The following Terraform resource exports the tunnel ID and other variables to `t
263222
content = <<-DOC
264223
# Ansible vars_file containing variable values from Terraform.
265224
tunnel_id: ${cloudflare_zero_trust_tunnel_cloudflared.gcp_tunnel.id}
266-
account: ${var.cloudflare_account_id}
267225
tunnel_name: ${cloudflare_zero_trust_tunnel_cloudflared.gcp_tunnel.name}
268226
tunnel_token: ${data.cloudflare_zero_trust_tunnel_cloudflared_token.gcp_tunnel_token.token}
269-
zone: ${var.cloudflare_zone}
270227
DOC
271228
272229
filename = "./tf_ansible_vars_file.yml"
@@ -298,38 +255,27 @@ Ansible playbooks are YAML files that declare the configuration Ansible will dep
298255
shell: wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
299256
- name: Depackage cloudflared.
300257
shell: sudo dpkg -i cloudflared-linux-amd64.deb
301-
- name: Create a cloudflared service directory.
302-
shell: mkdir -p /etc/cloudflared/
303-
- name: Create the config file for cloudflared and define the ingress rules for the tunnel.
304-
copy:
305-
dest: "/etc/cloudflared/config.yml"
306-
content: |
307-
tunnel: "{{ tunnel_id }}"
308-
credentials-file: /etc/cloudflared/cert.json
309-
logfile: /var/log/cloudflared.log
310-
loglevel: info
311-
ingress:
312-
- hostname: "ssh_app.{{ zone }}"
313-
service: ssh://localhost:22
314-
- service: http_status:404
315-
- name: Create the tunnel credentials file for cloudflared.
316-
copy:
317-
dest: "/etc/cloudflared/cert.json"
318-
content: |
319-
{
320-
"AccountTag" : "{{ account | quote }}",
321-
"TunnelID" : "{{ tunnel_id | quote }}",
322-
"TunnelName" : "{{ tunnel_name | quote }}",
323-
"TunnelSecret" : "{{ secret | quote }}"
324-
}
325258
- name: Install the tunnel as a systemd service.
326-
shell: cloudflared service install
259+
shell: "cloudflared service install {{ tunnel_token }}"
327260
- name: Start the tunnel.
328261
systemd:
329262
name: cloudflared
330263
state: started
331264
enabled: true
332265
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>
333279
```
334280
335281
[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.
@@ -362,4 +308,4 @@ It may take several minutes for the GCP instance and tunnel to come online. You
362308

363309
## 7. Test the connection
364310

365-
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

Comments
 (0)