DAJEEEEEE, STA ANDANDO (anche se con nginx e non con xmpp) E GODO UN CASINOOOO. ALLA FINE I PROBLEMI DI SSH ERANO SOLO DOVUTI ALLA FRETTA. E LASCIA UN PO' DI TEMPO A STI POVERI CONTAINER DI AVVIARSI
This commit is contained in:
parent
54eeb79ac9
commit
2d5fb2e77b
3 changed files with 24 additions and 45 deletions
|
@ -6,6 +6,19 @@
|
||||||
become: yes
|
become: yes
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
- name: Wait until SSH is fully ready (Ansible login confirms availability)
|
||||||
|
ansible.builtin.wait_for_connection:
|
||||||
|
timeout: 300 # fino a 5 minuti (essere generosi per bootstrap lento)
|
||||||
|
delay: 5 # aspetta 5s prima di cominciare i tentativi
|
||||||
|
|
||||||
|
|
||||||
|
- name: Ensure apt cache is updated (idempotent)
|
||||||
|
ansible.builtin.apt:
|
||||||
|
update_cache: yes
|
||||||
|
# non vogliamo che il primo apt rallenti la connessione dopo wait_for_connection,
|
||||||
|
# ma questo garantisce che i task successivi usino pacchetti aggiornati.
|
||||||
|
|
||||||
|
|
||||||
- name: Ensure SSH is installed
|
- name: Ensure SSH is installed
|
||||||
ansible.builtin.apt:
|
ansible.builtin.apt:
|
||||||
name: openssh-server
|
name: openssh-server
|
||||||
|
@ -28,14 +41,6 @@
|
||||||
notify: Restart SSH
|
notify: Restart SSH
|
||||||
|
|
||||||
|
|
||||||
- name: Disable DNS lookup to speed up SSH login
|
|
||||||
ansible.builtin.lineinfile:
|
|
||||||
path: /etc/ssh/sshd_config
|
|
||||||
regexp: '^#?UseDNS'
|
|
||||||
line: 'UseDNS no'
|
|
||||||
notify: Restart SSH
|
|
||||||
|
|
||||||
|
|
||||||
- name: Ensure .ssh directory exists
|
- name: Ensure .ssh directory exists
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: /root/.ssh
|
path: /root/.ssh
|
||||||
|
@ -53,21 +58,3 @@
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
|
|
||||||
|
|
||||||
- name: Configure SSH for key-only root login
|
|
||||||
ansible.builtin.blockinfile:
|
|
||||||
path: /etc/ssh/sshd_config
|
|
||||||
block: |
|
|
||||||
PermitRootLogin prohibit-password
|
|
||||||
PasswrodAuthentication no
|
|
||||||
UseDNS no
|
|
||||||
notify: Restart SSH
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
handlers:
|
|
||||||
- name: Restart SSH
|
|
||||||
ansible.builtin.service:
|
|
||||||
name: ssh
|
|
||||||
state: restarted
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
vars:
|
vars:
|
||||||
root_password: "{{ lookup('env', 'XMPP_PASSWORD') }}"
|
root_password: "{{ lookup('env', 'XMPP_PASSWORD') }}"
|
||||||
ssh_public_key: "{{ lookup('file', '~/.ssh/ansible.pub') }}"
|
ssh_public_key: "{{ lookup('file', '~/.ssh/ansible.pub') }}"
|
||||||
|
vmid: 121
|
||||||
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
|
@ -14,7 +15,7 @@
|
||||||
api_host: "{{ proxmox_url }}"
|
api_host: "{{ proxmox_url }}"
|
||||||
api_user: "{{ proxmox_user }}"
|
api_user: "{{ proxmox_user }}"
|
||||||
api_password: "{{ proxmox_password }}"
|
api_password: "{{ proxmox_password }}"
|
||||||
vmid: 121
|
vmid: "{{ vmid }}"
|
||||||
node: milan
|
node: milan
|
||||||
hostname: xmpp
|
hostname: xmpp
|
||||||
ostemplate: "local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst"
|
ostemplate: "local:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst"
|
||||||
|
@ -25,6 +26,7 @@
|
||||||
net0: "name=eth0,bridge=vmbr1,ip=10.10.0.21/16,gw=10.10.0.1"
|
net0: "name=eth0,bridge=vmbr1,ip=10.10.0.21/16,gw=10.10.0.1"
|
||||||
pubkey: "{{ ssh_public_key }}"
|
pubkey: "{{ ssh_public_key }}"
|
||||||
password: "{{ root_password }}"
|
password: "{{ root_password }}"
|
||||||
|
features: "nesting=1"
|
||||||
state: present
|
state: present
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
register: lxc_creation_result #booooh, capiremo questo che vuol dire. Intanto registriamolo... immagino...
|
register: lxc_creation_result #booooh, capiremo questo che vuol dire. Intanto registriamolo... immagino...
|
||||||
|
@ -35,30 +37,13 @@
|
||||||
api_host: "{{ proxmox_url }}"
|
api_host: "{{ proxmox_url }}"
|
||||||
api_user: "{{ proxmox_user }}"
|
api_user: "{{ proxmox_user }}"
|
||||||
api_password: "{{ proxmox_password }}"
|
api_password: "{{ proxmox_password }}"
|
||||||
vmid: 121
|
vmid: "{{ vmid }}"
|
||||||
node: milan
|
node: milan
|
||||||
state: started # Tutto questo blocco è riassumibile in questa riga
|
state: started # Tutto questo blocco è riassumibile in questa riga
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
when: lxc_creation_result.changed
|
when: lxc_creation_result.changed
|
||||||
|
|
||||||
|
|
||||||
# - name: Wait for container SSH to be available
|
|
||||||
# wait_for:
|
|
||||||
# host: 10.10.0.21
|
|
||||||
# port: 22
|
|
||||||
# timeout: 90
|
|
||||||
# delay: 10
|
|
||||||
# delegate_to: localhost
|
|
||||||
# when: lxc_creation_result.changed
|
|
||||||
|
|
||||||
|
|
||||||
- name: Wait until SSH is fully ready
|
|
||||||
ansible.builtin.wait_for_connection:
|
|
||||||
timeout: 180
|
|
||||||
delegate_to: xmpp01
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- name: Aggiungi container all'inventory dinamico
|
- name: Aggiungi container all'inventory dinamico
|
||||||
add_host:
|
add_host:
|
||||||
name: xmpp01
|
name: xmpp01
|
||||||
|
|
7
playbooks/test_nginx.yml
Normal file
7
playbooks/test_nginx.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
- name: Test provisioning nginx
|
||||||
|
hosts: xmpp01
|
||||||
|
gather_facts: false
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- nginx
|
Loading…
Add table
Add a link
Reference in a new issue