Compare commits
27 Commits
6d6f6691ba
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| cb5342d0b9 | |||
| 98bf9f3c25 | |||
| a71d196cc0 | |||
| fa263a4b27 | |||
| d706c92a2f | |||
| ed30cb748b | |||
| fa5ee9d085 | |||
| e1ea5b53d1 | |||
| c2736624d8 | |||
| 95fe09aa72 | |||
| 428516978c | |||
| bff09c8fab | |||
| af9a1417d4 | |||
| 52b4abee8c | |||
| 13d07f31b6 | |||
| 2eedffd23c | |||
| f880f5b8d5 | |||
| fa68e6b6a8 | |||
| da956e8ddd | |||
| 8fb2503018 | |||
| 82b4bd3e9c | |||
| 4537dcd27a | |||
| deb7676cce | |||
| 05ab960852 | |||
| 9f1ee6b80e | |||
| 27d447338d | |||
| 5262fff75c |
@@ -6,8 +6,7 @@
|
||||
become_user: root
|
||||
|
||||
vars:
|
||||
node_ip: "{{ hostvars['node0']['ansible_host'] }}"
|
||||
addc_hostname: "DC1"
|
||||
node_ip: "{{ hostvars['node0']['ansible_host'] }}"
|
||||
mac_address: "8E:90:31:DE:31:36"
|
||||
|
||||
container_id: 200
|
||||
@@ -26,19 +25,29 @@
|
||||
container_onboot: 1
|
||||
container_protection: 0
|
||||
container_unprivileged: 1
|
||||
# container_tags: "ansible_managed,test"
|
||||
container_pubkey: "{{ ssh_public_keys[0] }}"
|
||||
container_tags:
|
||||
- ansible_managed
|
||||
- test
|
||||
|
||||
tasks:
|
||||
|
||||
- name: Create LXC container using pct command on shell
|
||||
- name: Combine SSH public keys into one file
|
||||
ansible.builtin.copy:
|
||||
dest: "{{ ssh_keys_file }}"
|
||||
content: |
|
||||
{% for key in ssh_public_keys %}
|
||||
{{ key }}
|
||||
{% endfor %}
|
||||
mode: '0644'
|
||||
|
||||
- name: Create LXC container {{ container_hostname }} with id {{ container_id }} using pct command on shell
|
||||
ansible.builtin.shell: |
|
||||
pct create {{ container_id }} {{ container_template }} \
|
||||
-ostype {{ container_ostype }} \
|
||||
-hostname {{ container_hostname }} \
|
||||
-password {{ container_password }} \
|
||||
-ssh-public-keys {{ ssh_keys_file }} \
|
||||
-cores {{ container_cores }} \
|
||||
-memory {{ container_memory }} \
|
||||
-swap {{ container_swap }} \
|
||||
@@ -52,5 +61,88 @@
|
||||
-features {{ container_features }}
|
||||
args:
|
||||
creates: "/etc/pve/lxc/{{ container_id }}.conf"
|
||||
|
||||
no_log: true
|
||||
|
||||
# -rootfs {{ container_storage }}:{{ container_id }}/vm-{{ container_id }}-disk-0.raw,size=7G \
|
||||
|
||||
# -timezone: {{ localization_timezone }} \
|
||||
|
||||
- name: Check if LXC container {{ container_hostname }} is running
|
||||
ansible.builtin.command:
|
||||
cmd: pct status {{ container_id }}
|
||||
register: pct_status
|
||||
changed_when: false
|
||||
|
||||
- name: Start the LXC container {{ container_hostname }} if stopped
|
||||
ansible.builtin.command:
|
||||
cmd: pct start {{ container_id }}
|
||||
when: "'status: stopped' in pct_status.stdout"
|
||||
register: start_result
|
||||
changed_when: "'status: stopped' in pct_status.stdout"
|
||||
|
||||
- name: Wait until container has an IP address
|
||||
ansible.builtin.shell: "pct exec {{ container_id }} -- hostname -I | awk '{print $1}'"
|
||||
register: lxc_ip
|
||||
until: lxc_ip.stdout != ""
|
||||
retries: 10
|
||||
delay: 5
|
||||
changed_when: false
|
||||
failed_when: lxc_ip.stdout == ""
|
||||
|
||||
- name: Wait for SSH to become available
|
||||
ansible.builtin.wait_for:
|
||||
host: "{{ lxc_ip.stdout }}"
|
||||
port: 22
|
||||
delay: 5
|
||||
timeout: 60
|
||||
retries: 10
|
||||
delay: 5
|
||||
changed_when: false
|
||||
|
||||
# --- DC‑1 Provisioning Play --------------------------------------------
|
||||
|
||||
- name: Provision dc1 LXC
|
||||
hosts: dc1
|
||||
gather_facts: false
|
||||
become: true
|
||||
|
||||
tasks:
|
||||
|
||||
# - name: Ensure SSH authorized keys are present
|
||||
# ansible.posix.authorized_key:
|
||||
# user: root
|
||||
# key: "{{ item }}"
|
||||
# state: present
|
||||
# loop: "{{ ssh_public_keys }}"
|
||||
|
||||
|
||||
- name: Install useful packages
|
||||
ansible.builtin.package:
|
||||
name:
|
||||
- nano
|
||||
- tzdata
|
||||
# - openssh-server
|
||||
state: present
|
||||
|
||||
- name: Update all packages, autoclean, and autoremove
|
||||
ansible.builtin.apt:
|
||||
name: "*"
|
||||
state: latest
|
||||
autoclean: yes
|
||||
autoremove: yes
|
||||
purge: true
|
||||
|
||||
- name: Set timezone to {{ localization_timezone }}
|
||||
community.general.timezone:
|
||||
name: "{{ localization_timezone }}"
|
||||
notify: Restart sshd
|
||||
tags: [timezone]
|
||||
|
||||
# --- Global Handlers ----------------------------------------------
|
||||
|
||||
handlers:
|
||||
- name: Restart sshd
|
||||
ansible.builtin.service:
|
||||
name: ssh
|
||||
state: restarted
|
||||
when: localization_timezone | bool
|
||||
Reference in New Issue
Block a user