Ansible Script 추가

This commit is contained in:
ByeonJungHun
2023-12-19 13:36:16 +09:00
parent 0273450ff6
commit 05cb8d9269
2610 changed files with 281893 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
- name: "Create temporary directory for key manipulation"
tempfile:
state: directory
suffix: keys
register: tempdir
when:
- install == True or update == True
- remove == False
- name: "Include Teleport Agent Install"
include_tasks: teleport_install.yml
tags: install
when:
- install == True
- name: "Include Teleport Agent update"
include_tasks: teleport_update.yml
tags: remove
when:
- update == True
- name: "Remove temporary directory for key manipulation"
file:
path: "{{ tempdir.path }}"
state: absent
when:
- install == True or update == True
- name: "Include Teleport Agent remove"
include_tasks: teleport_remove.yml
tags: remove
when:
- remove == True

View File

@@ -0,0 +1,25 @@
---
- name: "Run tctl nodes add and capture the output"
command: tctl nodes add
register: tctl_output
changed_when: false
delegate_to: 127.0.0.1
- name: "Extract token and ca_pin"
set_fact:
get_join_token: "{{ (tctl_output.stdout | regex_search('--token=(\\S+)', '\\1'))[0] }}"
get_ca_pin: "{{ (tctl_output.stdout | regex_search('--ca-pin=(\\S+)', '\\1'))[0] }}"
- name: "Debug extracted values"
debug:
msg:
- "join_token: {{ get_join_token }}"
- "ca_pin: {{ get_ca_pin }}"
- name: "Create Teleport install script"
template:
src: install-node.sh.j2
dest: "{{ tempdir.path }}/install-node.sh"
- name: "Run Teleport Install Script"
command: "bash {{ tempdir.path }}/install-node.sh"

View File

@@ -0,0 +1,27 @@
---
- name: "Remove Teleport on RedHat-based systems"
yum:
name: teleport
state: absent
when: ansible_os_family == "RedHat"
- name: "Remove Teleport on Debian-based systems"
apt:
name: teleport
state: absent
when: ansible_os_family == "Debian"
- name: "Remove Teleport directories and files"
file:
path: "{{ item }}"
state: absent
with_items:
- /var/lib/teleport
- /etc/teleport.yaml
- /usr/local/bin/teleport
- /usr/local/bin/tctl
- /usr/local/bin/tsh
- name: "Kill Teleport processes"
command: pkill -9 teleport
ignore_errors: yes

View File

@@ -0,0 +1,47 @@
---
- name: "Run token the output"
shell: "cat /etc/teleport.yaml | grep 'token_name:' | awk '{print $2}'"
register: token_output
changed_when: false
ignore_errors: true
- name: "Run ca_pin the output"
shell: "cat /etc/teleport.yaml | grep 'ca_pin:' | awk '{print $2}'"
register: ca_output
changed_when: false
ignore_errors: true
- name: "Extract token and ca_pin"
set_fact:
get_join_token: "{{ token_output.stdout }}"
get_ca_pin: "{{ ca_output.stdout }}"
- name: "Debug extracted values"
debug:
msg:
- "join_token: {{ get_join_token }}"
- "ca_pin: {{ get_ca_pin }}"
- name: "Update Teleport yaml"
template:
src: teleport.yaml.j2
dest: "/etc/teleport.yaml"
- name: "Update Teleport on RedHat-based systems"
yum:
name: teleport
state: latest
when: ansible_os_family == "RedHat"
notify:
- Reload systemd configuration
- Restart teleport service
- name: "Update Teleport on Debian-based systems"
apt:
name: teleport
state: latest
when: ansible_os_family == "Debian"
notify:
- Reload systemd configuration
- Restart teleport service