👁️
pierreinside
  • Introduction
  • Workbench
    • VirtualBox
    • Linux
      • Linux-Paketverwaltung
      • Linux Initialisierung
      • Ubuntu 14.10 LTS
      • Ubuntu 16.04 LTS
      • Ubuntu 18.04 LTS
      • Ubuntu 20.04 LTS
      • Ubuntu - Netzwerk
    • Konsole
      • ssh
      • zsh
      • cygwin
      • Babun
      • terminator
      • Terminal Multiplexer
      • Linux Tools
    • awesome
    • Entwicklungsumgebungen
      • Texteditors
      • Visual Studio Code
      • IntelliJ - IDEA
  • Softwareentwicklungsprozess
    • Schätzungen
    • Eventstorming
    • OKR
  • Architektur
    • Uncle Bob
    • Microservices
    • NoSQL
      • ElasticSearch
    • Hystrix
    • Reactive Programming
    • AngularJS
    • Service Mesh
  • Networking
    • Dependency Injection
  • Programming
    • Java Core/EE
      • Java 8
      • Java Annotationen
      • Bean Validation
      • Enterprise Java Beans Specification
      • Dependency Injection
    • JRebel
    • Webservices
      • HTTP
      • REST
      • Spring MVC REST
      • Swagger
      • Postman
    • Spring Ecosystem
      • Spring Core
      • Spring Boot
        • Programming
        • Production Ready
        • Testing
      • Spring Cloud
      • Spring Cloud Config
      • Spring MVC
      • Spring Data
      • Spring Petclinic
    • NodeJS
    • UI-Technologie
      • Thymeleaf
      • ionic
      • Web Fonts
      • Jinja Templates
      • Twitter Bootstrap
    • Python Ecosystem
      • Python Libraries
      • Python Testing
      • Python Best-Practices
      • Python Snippets
      • Python Selenium
      • Kivy UI
      • FastAPI
      • Typer CLI
      • Django
    • Groovy
    • Persistenz
      • Transactions
        • Java TX
        • JPA TX
      • TX Handling
      • JPA
        • Eclipse Link
      • MySQL
        • MySQL Performance
        • Docker MySQL
      • Hazelcast
    • Glassfish
    • YAML
    • Angular
    • Camel
    • Zeichenkodierung
    • Kinder lernen Programmieren
  • Testen
    • Easymock
    • Mockito
  • Performance & Scalability
    • Java Performance
      • Heapdump Analysis
    • Java Concurrency
    • Instana
  • Sicherheit
    • Authentifizierung
      • OpenID Connect
      • Web-Authentication API
    • Authorisierung
      • OAuth
      • SAML
    • Spring Security
    • Zertifikate
    • Kali Linux
    • VPN
    • Zero-Trust-Networks
  • Build und Deployment
    • Maven
    • Bamboo
    • Jenkins
      • Jenkins Pipelines
      • Jenkins Pipelines Tips und Tricks
      • Jenkins-configuration-as-Code
      • Jenkins IDE
    • Travis CI
    • Shellprogrammierung
      • jq - JSON Parsing
    • Konfiguration Management
    • Vagrant
      • Vagrant-Ansible-Integration
      • Vagrant Box bauen
    • Ansible
      • Getting Started
      • Ansible Details
    • Saltstack
    • LinuxKit
    • Container
      • Docker
        • Docker Getting Started
        • Debugging Docker
        • Docker Build
        • Docker Registry
        • Docker run
          • docker run
          • docker network
        • Docker Compose
        • docker machine
        • Docker@Windows
        • Docker Host
        • Docker Scaling
        • Docker Ressources
        • Docker Logging
        • windowsContainer
      • Cloud Deployment Provider
        • AWS
          • Anwendungsdeployment
          • Workload
          • Permissions
          • Netzwerke
          • AWS CLI
            • aws-vault
          • RDS
          • Static Website Hosting
          • EKS - Elastic Kubernetes Service
          • S3
        • Google Cloud Platform
      • Docker Orchestrierung
        • CoreOS
        • Kubernetes
          • microK8s
          • minikube
          • autoscaler
          • Docker
          • k9s
        • Nomad
    • PHP
  • Operations
    • Proxy
      • NGINX
    • DNS
    • Logging
      • Graylog
      • Fluentd
    • Monitoring
      • Grafana
    • Infrastructure-as-Code
      • Terraform
        • AWS-Provider
        • GitHub-Provider
      • Packer
    • Deployment
      • Vault
      • Consul
        • Consul Template
      • Fabio
  • Rechtliches
    • Software-Lizenzen
  • Git Ecosystem
    • Git
      • Git Lifecycle Hooks
    • GitHub
      • GitHub Organizations
    • GitHub Actions
    • GitHub Pages
    • GitHub CLI
    • GitHub Copilot
    • GitHub-AWS OIDC
    • GitBook
    • GitLab
    • Bitbucket/Stash
  • Publishing
    • WordPress
    • Markdown
    • Static Site Generators
      • Hugo
      • Jekyll
    • Tiddly Wiki
    • Leanpub
    • Animationsfilme
  • Storage
    • Synology 2012
    • Synology 2021
  • Collaboration
    • Übersicht
    • Microsoft Teams
  • Konferenzen
    • Velocity Berlin 2019
  • IT mit Kindern
    • Projekt Sportstracker
    • Scratch
    • Pico Spielekonsole
  • Schule
    • Mathematik
  • Misc
    • Foto/Video
      • Foto/Video Sammlung bis 2023
        • Handbrake
        • Onedrive
      • Foto/Video Sammlung ab 2024
      • Gopro
      • Panasonic FZ1000 ii
        • als Webcam
      • AV Receiver
      • Videos erstellen
        • OBS Studio
        • Touch Portal
        • Game-Streaming
      • Kameratasche
      • Kamera 2020
    • Handy
      • 2016
      • 2018
      • 2019
      • 2021
      • 2022
    • Computer
      • Laptop
        • 2018
        • Chromebook
      • Monitor
        • 4k
      • Software
        • Command Line Interface
        • Google API
        • Plant UML
        • Chromium
        • Passwort-Manager
        • GPG
      • Dell CNF 2665 Farbdrucker
      • Dockingstation
      • Gaming PC 2021
      • Mobiles Büro
      • Mobiles Internet
      • Mobiler Router
    • Beamer Benq W1000+
    • Spielekonsole
      • 2017
        • Playstation 4
      • Pico Spielekonsole
    • Gadgets
      • iPad Pro 2015 und 2016
      • iPad Air 2024
      • Macbook Pro
      • Smartwatch
      • Slate
      • Mudi
    • Fahrrad
      • Jonas 2018
      • SQLab
    • Auto
      • Auto 2022
      • Camping
        • Camping Touren Ideen
          • Camping Tour - Gardasee 2021
        • Camper
          • Camper klein - keine Stehhöhe
            • VW Bus Erfahrungen
          • Camper gross - Stehhöhe
    • Haus
      • Klimaanlage
      • Swimming Pool
      • Quick Mill Orione 3000
      • Spülmaschine 2021
      • Hebe-Schiebetür
      • Gasgrill
      • Minibar / Mini-Kühlschrank
      • Glasfaseranschluss (Fiber-to-the-Home)
      • Smart-Home
        • Raspberry Pi
        • Heimnetzwerk
      • Homeoffice
      • Energie
        • Solar
        • Wärmepumpe
    • Freizeit
      • Musik Streaming
      • Sky
      • Online Lernplattformen
      • eScooter - ePowerFun
    • Fußball
      • Meine Arbeit als Fußball-Trainer
      • Fußball Tools
      • DFB Talentförderung
    • Google Impact Challenge
  • Englisch
Powered by GitBook
On this page
  • Windows-Host
  • Remote Ansible Provider ... funktioniert nicht
  • Local Ansible Provider
  • Fehlersuche
  • vagrant up --debug
  • ansible.verbose = true

Was this helpful?

  1. Build und Deployment
  2. Vagrant

Vagrant-Ansible-Integration

Vagrant erlaubt das Provisioning von Maschinen über die Provider

  • ansible: das ist der typische Remote-Ansatz

  • ansible_local: hierbei erfolgt die Ausführung des Playbooks lokal auf dem Guest-System


Windows-Host

Für eine komplette Automatisierung meiner Workbench (VirtualBox-Linux-Image) hatte ich die Idee, mittels Vagrant und Ansible ein komplett automatisiertes Setup zu scripten.

Remote Ansible Provider ... funktioniert nicht

  • http://docs.ansible.com/ansible/guide_vagrant.html

Der typische Ansible-Ansatz ermöglicht die Ausführung von Kommandos via ssh. Insofern paßt es perfekt in ein Vagrant-Host/Guest-Szenario - der Host sendet via ssh (wird von Vagrant eh schon konfiguriert) die entsprechenden Shell-Kommandos zum Guest.

Einzige Voraussetzung ist die Installation von Ansible auf dem Host-System. Leider wird diese Einschränkung für Windows-Host-Systeme zum Ausschlußkriterium, denn Ansible wird für Windows nicht unterstützt. Für mein Workbench-Szenario kam diese Lösung demnach nicht in Frage.

Local Ansible Provider

In diesem Fall muß Ansible nicht auf dem Host-System, sondern auf dem Guest-System (= Linux-System) installiert werden. Das erfolgt ...

  • entweder automatisch durch die Option install (ACHTUNG: funktioniert nicht mit Vagrant 1.8.1, wohl aber mit 1.8.4 ... https://github.com/mitchellh/vagrant/issues/6858):

    config.vm.provision "ansible_local" do |ansible| ansible.playbook = "playbook.yml" install = true end

  • oder per Shellscript-Provisioning im Vagrantfile - vorher muß natürlich das entsprechende Repository im Guest-System eingetragen sein (beim install_mode = default) oder Ansible wird über den Python-Paketmanager installiert (beim install_mode = pip):

    config.vm.provision "shell", inline: <<-SHELL sudo apt-get install -y ansible SHELL

Die ansible_local Variante hat den Charme, daß Ansible auf dem Host-System nicht installiert werden muß und am Ende hat man auf dem Guest-System einen vollwertigen Ansible-Controller. Das hat folgende Vorteile:

  • das Host-System wird nicht verändert

  • das Ansible-Provisioning einer Vagrant-Maschine kann auch unter Windows KOMPLETT automatisiert (scriptbasiert) erfolgen

  • über den Ansible-Controller können weitere Zielsysteme gesteuert werden. Dieses Setup entspricht dann beispielsweise

Das abzuspielende Playbook wird vom Guest über den den Shared-Folder. Die Location ist über provisioning_path konfigurierbar. Die Defaulteinstellung gilt provisioning_path=., d. h. das Playbook liegt parallel zum Vagrantfile und ist dann unter /vagrant/ ins Gast-System eingebunden.

Blue-Print: zentraler Ansible-Controller

Ich halte den Aufbau eines zentralen Ansible-Managment-Knotens für empfehlenswert. Dieser Management-Knoten wird per ansible_local mit ansible.install = true komfortabel aufgebaut. Von dort aus wird das Playbook wie üblich gegen die Zielsysteme (per ssh-Kommando) abgespielt.

So könnte das dazu passende Vagrantfile aussehen (https://www.vagrantup.com/docs/provisioning/ansible_local.html):

Vagrant.configure("2") do |config|

  config.vm.box = "ubuntu/trusty64"

  config.vm.define "node1" do |machine|
    machine.vm.network "private_network", ip: "192.168.1.10"
  end

  config.vm.define "node2" do |machine|
    machine.vm.network "private_network", ip: "192.168.1.20"
  end
  
  config.vm.define 'management' do |machine|
    machine.vm.network "private_network", ip: "192.168.1.99"

    machine.vm.provision :ansible_local do |ansible|
      ansible.playbook       = "myPlaybook.yml"
      ansible.install        = true
      ansible.inventory_path = "inventory"
    end
  end

end

Dabei werden drei Maschinen aufgebaut. Zuerst die beiden Knoten node1 und node2 (als Repräsentaten beliebiger Solution-Komponenten), auf denen zunächt kein weiteres Provisioning definiert ist. Zum Schluß wird der Ansible-Controller management erzeugt, von dem aus das Provisioning aller Knoten über das Playbook myPlaybook getriggert wird.

config.vm.synced_folder "./", "/vagrant", 
    id: "vagrant-root", 
    owner: "vagrant", 
    group: "vagrant", 
    mount_options: ["dmode=700,fmode=600"]

Aus meiner Sicht ist das eh die beste Konfiguration, denn niemand soll den Shared-Folder . (in dem das Vagrantfile und weitere Skripte/Konfigurationen für das Provisioning liegen) ändern können (Vorsicht: Seiteneffekte). Sollte der Gast Daten mit dem Host austauschen wollen, dann kann ein weiterer Shared-Folder konfiguriert werden.


Fehlersuche

vagrant up --debug

Der Standard Vagrant-Mechanismus.

ansible.verbose = true

Das leidige Thema ... auf jeden Fall sollte man den Schalter ansible.verbose = true im Vagrantfile setzen:

machine.vm.provision "ansible_local" do |ansible|
    ansible.install  = true
    ansible.playbook = "playbook.yml"
    ansible.limit = "all"
    ansible.verbose = true
end        

Dadurch werden die auf dem Guest ausgeführten Befehle auf der Konsole angezeigt. Sieht ein wenig komisch aus:

MANAGEMENT: Running ansible-playbook...
cd /vagrant/management/ansible &&
  PYTHONUNBUFFERED=1 
  ANSIBLE_FORCE_COLOR=true 
  ansible-playbook 
  --limit="all" 
  --inventory-file=
    /vagrant/management/ansible/ansible-inventory 
  -v 
  playbook.yml
Using /vagrant/management/ansible/ansible.cfg as config file

Mit diesen Informationen lässt sich die Suche fortsetzen. Per vagrant ssh anmelden und das Kommando ausführen lassen ... allerdings mit der Ansible-Option -vvvv (sehr geschwätzig!!!) ... also das:

cd /vagrant/management/ansible &&
  PYTHONUNBUFFERED=1 
  ANSIBLE_FORCE_COLOR=true 
  ansible-playbook 
  --limit="all" 
  --inventory-file=
    /vagrant/management/ansible/ansible-inventory 
  -v 
  playbook.yml
  -vvvv

Das erspart zumindest mal das teure Neuaufsetzen des gesamten Deployments.

PreviousVagrantNextVagrant Box bauen

Last updated 3 years ago

Was this helpful?

In dem Beispiel (https://www.vagrantup.com/docs/provisioning/ansible_local.html) wird versucht, die Private-Keys des User vagrant auf den jeweiligen Maschinen (node1, node2) für den ssh-connect des Ansible-Controllers (management) zu verwenden. Das ist prinzipell eine exzellente Idee, weil man sich so spart den Public-Key des Users vagrant auf den beiden Knoten zu hinterlegen. ABER: ssh-clients verhindern die Nutzung der Private-Key-Authentifizierung, wenn die Permissions falsch gesetzt sind (Stichwort 600/700 ... siehe ssh-Kapitel). Deshalb müssen die Zugriffsrechte für den Shared-Folder folgendermaßen gesetzt sein:

Windows-Vagrant-Ansible-Integration