30 lines
981 B
YAML
30 lines
981 B
YAML
variables:
|
|
ANSIBLE_HOST_KEY_CHECKING: "False"
|
|
|
|
stages:
|
|
- deploy
|
|
|
|
deploy:
|
|
stage: deploy
|
|
image: python:3.11-slim
|
|
|
|
before_script:
|
|
- apt-get update && apt-get install -y openssh-client ssh
|
|
- pip install Ansible
|
|
- ansible-galaxy collection install --force community.docker:3.13.6
|
|
- mkdir -p ~/.ssh
|
|
- echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
|
- chmod 600 ~/.ssh/id_rsa
|
|
- echo -e "Host *\n\tIdentityFile ~/.ssh/id_rsa\n\tIdentitiesOnly yes\n\tStrictHostKeyChecking no\n\tUserKnownHostsFile=/dev/null" > ~/.ssh/config
|
|
|
|
|
|
script:
|
|
- echo "🔍 Checking SSH key setup..."
|
|
- head -5 ~/.ssh/id_rsa | cat -v
|
|
- ls -l ~/.ssh/id_rsa
|
|
- file ~/.ssh/id_rsa || echo "file command not available"
|
|
- echo "🔐 Testing SSH connection..."
|
|
- ssh -i ~/.ssh/id_rsa root@ansible01vt.smartika.azubi-osa.noris.de 'echo ✅ SSH connection successful'
|
|
- echo "🚀 Running Ansible Playbook..."
|
|
- ansible-playbook -i inventory.yaml playbook.yaml
|