diff --git a/roles/role/vars/secrets.yml b/.ansible/.lock similarity index 100% rename from roles/role/vars/secrets.yml rename to .ansible/.lock diff --git a/Dockerfile b/Dockerfile index d4bb7e9..627ecb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,52 @@ -FROM python:3.9-slim +# Use the official Python 3.12.9 Bullseye image as the base +FROM python:3.12.9-bullseye -# Устанавливаем зависимости -RUN apt-get update && apt-get install -y \ +# Set environment variables +ENV PYTHONUNBUFFERED=1 + +# Install system dependencies +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ git \ - curl \ - docker.io \ - docker-compose \ + ssh \ + gcc \ + libffi-dev \ + libssl-dev \ + make \ + sudo \ sshpass \ && rm -rf /var/lib/apt/lists/* -RUN pip3 install --no-cache-dir ansible ansible-lint ansible-vault molecule docker molecule-docker +# Install Docker CLI +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + curl \ + gnupg \ + lsb-release \ + && mkdir -p /etc/apt/keyrings \ + && curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian bullseye stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \ + && apt-get update && \ + apt-get install -y --no-install-recommends \ + docker-ce-cli \ + && rm -rf /var/lib/apt/lists/* -# Устанавливаем Docker CLI -RUN curl -fsSL https://get.docker.com | sh +# Install Python dependencies for Ansible and Molecule +RUN pip install --upgrade pip && \ + pip install \ + ansible \ + ansible-lint \ + ansible-vault \ + molecule \ + molecule-docker \ + molecule-plugins ansible-compat \ + docker + + +# Set the working directory WORKDIR /ansible -ENTRYPOINT ["/bin/bash"] + +# Default command +CMD ["/bin/bash"] \ No newline at end of file diff --git a/Makefile b/Makefile index 3d25be6..9502077 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ build: rebuild: docker compose build --no-cache $(c) docker compose down - docker compose up -d +# docker compose up -d # Создание и запуск docker-контейнеров up: @@ -62,14 +62,17 @@ test: ## Запуск тестов с molecule docker compose run --rm ansible bash -c "molecule test" lint: ## Проверка кода с ansible-lint - docker compose run --rm ansible sh -c "ansible-lint roles/role" + docker compose run --rm ansible bash -c "ansible-lint roles/role" -vault: ## Шифрование/дешифрование с ansible-vault - docker compose run --rm ansible sh -c "ansible-vault edit --vault-password-file vault-password.txt vars/secrets.yml" +vault_create: ## Шифрование/дешифрование с ansible-vault + docker compose run --rm ansible bash -c "ansible-vault create --encrypt-vault-id default --vault-password-file vault-password.txt roles/role/vars/secrets.yml" + +vault_edit: ## Шифрование/дешифрование с ansible-vault + docker compose run --rm ansible bash -c "ansible-vault edit --vault-password-file vault-password.txt roles/role/vars/secrets.yml" deploy: test ## Деплой на реальные машины, если тест прошел успешно @echo "Deploying roles to production..." - docker compose run --rm ansible sh -c "ansible-playbook -i inventory/production deploy.yml --vault-password-file vault-password.txt" + docker compose run --rm ansible /usr/bin/sh -c "ansible-playbook -i inventory/production deploy.yml --vault-password-file vault-password.txt" #################################################################################################### # Работа с Git diff --git a/ansible.cfg b/ansible.cfg index 263f728..33d3bd5 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,6 +1,7 @@ [defaults] -inventory = /workspace/inventory -vault_password_file = /workspace/vault_password_file -remote_user = devops +inventory = /ansible/inventory +vault_password_file = /ansible/vault_password.txt +remote_user = ansible host_key_checking = False -enable_plugins = yaml, ini \ No newline at end of file +enable_plugins = yaml, ini +roles_path = /ansible/roles \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 464db8e..fde264c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -4,6 +4,9 @@ services: container_name: ansible volumes: - .:/ansible + - /var/run/docker.sock:/var/run/docker.sock environment: - ANSIBLE_VAULT_PASSWORD_FILE=/ansible/vault-password.txt - tty: true \ No newline at end of file + tty: true + privileged: true + working_dir: /ansible \ No newline at end of file diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index ce61f6b..b84d23e 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -2,4 +2,4 @@ - name: Converge hosts: all roles: - - role: role + - role: /ansible/roles/role diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 31ffe92..d26a736 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -1,6 +1,9 @@ --- dependency: name: galaxy + enabled: true + options: + requirements-file: /ansible/requirements.yml driver: name: docker platforms: diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index e69de29..0470683 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -0,0 +1,11 @@ +--- +- name: Prepare + hosts: all + tasks: + - name: Install required packages + debug: + msg: "Hello, Prepare!" +# apt: +# name: +# - git +# state: present \ No newline at end of file diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index e69de29..d7adc4f 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -0,0 +1,7 @@ +--- +- name: Prepare + hosts: all + tasks: + - name: Install required packages + debug: + msg: "Hello, Verify!" \ No newline at end of file diff --git a/requirements.yaml b/requirements.yaml deleted file mode 100644 index df49557..0000000 --- a/requirements.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -- src: geerlingguy.nginx - version: 3.1.0 -- src: geerlingguy.docker - version: 6.0.1 \ No newline at end of file diff --git a/requirements.yml b/requirements.yml new file mode 100644 index 0000000..d33abdd --- /dev/null +++ b/requirements.yml @@ -0,0 +1,9 @@ +--- +collections: + - name: maxhoesel.proxmox + version: 5.0.1 + - name: community.general + version: 6.0.0 + - name: ansible.posix + version: 1.4.0 +