tech:ansible_vagrant_et_docker
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| tech:ansible_vagrant_et_docker [2025/05/31 18:33] – Jean-Baptiste | tech:ansible_vagrant_et_docker [2026/06/07 19:12] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Ansible Vagrant et Docker | ||
| + | |||
| + | ## Docker | ||
| + | |||
| + | ### Install | ||
| + | |||
| + | #### Proxy | ||
| + | |||
| + | Voir [[Notes - docker - proxy]] | ||
| + | |||
| + | #### Général | ||
| + | |||
| + | Ajout du compte au groupe **docker** | ||
| + | |||
| + | ~~~bash | ||
| + | adduser jean docker | ||
| + | ~~~ | ||
| + | |||
| + | **Attention, | ||
| + | |||
| + | Exemple | ||
| + | ~~~bash | ||
| + | docker run -ti --privileged -v /:/host fedora chroot /host | ||
| + | ~~~ | ||
| + | |||
| + | Voir http:// | ||
| + | |||
| + | |||
| + | ### Conf conteneur | ||
| + | |||
| + | `Dockerfile` | ||
| + | ~~~bash | ||
| + | FROM debian: | ||
| + | |||
| + | #ENV http_proxy | ||
| + | #ENV https_proxy http:// | ||
| + | |||
| + | ARG https_proxy | ||
| + | ARG http_proxy | ||
| + | |||
| + | ENV DEBIAN_FRONTEND noninteractive | ||
| + | ENV TERM linux | ||
| + | ENV LANG C.UTF-8 | ||
| + | ENV LANGUAGE C.UTF-8 | ||
| + | ENV LC_ALL C.UTF-8 | ||
| + | |||
| + | RUN echo "deb http:// | ||
| + | RUN (apt-get update && apt-get upgrade -y -q && apt-get dist-upgrade -y -q && apt-get -y -q autoclean && apt-get -y -q autoremove) | ||
| + | RUN apt-get install -q -y --no-install-recommends openssh-server python-minimal tmux bash locales sudo vim supervisor | ||
| + | RUN apt-get install -q -y --no-install-recommends -t jessie-backports ansible | ||
| + | |||
| + | RUN (locale-gen fr_FR.UTF-8 UTF-8 && dpkg-reconfigure locales) | ||
| + | |||
| + | RUN mkdir -p / | ||
| + | RUN mkdir /root/.ssh | ||
| + | RUN echo " | ||
| + | |||
| + | COPY sshd.conf / | ||
| + | |||
| + | EXPOSE 22 | ||
| + | ENTRYPOINT ["/ | ||
| + | ~~~ | ||
| + | |||
| + | Conf supervisord | ||
| + | |||
| + | `sshd.conf` | ||
| + | ~~~ini | ||
| + | [program: | ||
| + | directory=/ | ||
| + | command=/ | ||
| + | autostart=true | ||
| + | autorestart=true | ||
| + | user = root | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | #docker build --no-cache -t plop --build-arg http_proxy=http:// | ||
| + | docker build -t plop --build-arg http_proxy=http:// | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Vagrant | ||
| + | |||
| + | `Vagrantfile` | ||
| + | ~~~ruby | ||
| + | Vagrant.configure(" | ||
| + | config.vm.provider " | ||
| + | #d.image = " | ||
| + | d.remains_running = false | ||
| + | d.build_dir = " | ||
| + | d.has_ssh = true | ||
| + | d.create_args = [' | ||
| + | end | ||
| + | config.ssh.username = " | ||
| + | config.ssh.private_key_path = " | ||
| + | |||
| + | config.vm.provision " | ||
| + | ansible.playbook = " | ||
| + | ansible.extra_vars = { | ||
| + | hostname: " | ||
| + | } | ||
| + | end | ||
| + | |||
| + | end | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ## Autre | ||
| + | |||
| + | Un Makefile pour nous simplifier la vie | ||
| + | |||
| + | `Makefile` | ||
| + | ~~~make | ||
| + | |||
| + | FicListYaml = $(shell find . -type f -iname " | ||
| + | FicListPlayBook = $(shell echo play*.yml) | ||
| + | |||
| + | check: | ||
| + | |||
| + | # Check YAML syntax | ||
| + | check-yaml: | ||
| + | for Fic in $(FicListYaml); | ||
| + | ansible-lint " | ||
| + | done | ||
| + | |||
| + | check-ansible: | ||
| + | for Fic in $(FicListPlayBook); | ||
| + | ansible-playbook --check " | ||
| + | done | ||
| + | |||
| + | apply: | ||
| + | for Fic in $(FicListPlayBook); | ||
| + | ansible-playbook " | ||
| + | done | ||
| + | |||
| + | # Check idempotent | ||
| + | check-active: | ||
| + | $(eval changed := $(shell ansible-playbook play-fi.yml | tail -2 | sed -e ' | ||
| + | @if [ " | ||
| + | echo "ERR NO idempostent"; | ||
| + | false ;\ | ||
| + | fi | ||
| + | |||
| + | clean: | ||
| + | rm -f *.retry | ||
| + | vagrant destroy -f | ||
| + | |||
| + | build: | ||
| + | vagrant up --provider=docker | ||
| + | |||
| + | status: | ||
| + | vagrant global-status | ||
| + | docker ps | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | |||
| + | ## Pb | ||
| + | |||
| + | La commande **hostname** échoue dans un Docker | ||
| + | |||
| + | J'ai dû utiliser la clause **WHEN** | ||
| + | ~~~yaml | ||
| + | - name: define hostname | ||
| + | hostname: name=' | ||
| + | when: ansible_virtualization_type != " | ||
| + | ~~~ | ||
| + | |||
| + | La modification du fichier /etc/hosts via **lineinfile** pose également pb. | ||
| + | |||
| + | ~~~ | ||
| + | Could not replace file: / | ||
| + | ~~~ | ||
| + | |||
| + | https:// | ||
| + | |||
