Ich habe a playbook to install PythonBrew. Um dies zu tun, muss ich die Shell-Umgebung ändern. Da Shell Schritte in ansible nicht persistent sind, habe ich export PYTHONBREW_ROOT=${pythonbrew.root}; source ${pythonbrew.root}/etc/bashrc;
bis Anfang jedes meiner PythonBrew bezogene Befehle vorangestellt wird:Wie wird in Ansible das Umgebungsschlüsselwort verwendet?
- name: Install python binary
shell: export PYTHONBREW_ROOT=${pythonbrew.root}; source ${pythonbrew.root}/etc/bashrc; pythonbrew install ${python.version}
executable=/bin/bash
- name: Switch to python version
shell: export PYTHONBREW_ROOT=${pythonbrew.root}; source ${pythonbrew.root}/etc/bashrc; pythonbrew switch ${python.version}
executable=/bin/bash
Ich möchte, dass die Redundanz beseitigen. Auf der Ansible discussion group wurde ich das Schlüsselwort environment
verwiesen. Ich habe mir die examples in the documentation angesehen und es klickt nicht für mich. Das Umgebungs-Keyword sieht für mich nicht viel anders aus als jede andere Variable.
Ich habe nach anderen Beispielen gesucht, aber konnte nur this very simple example finden.
Kann jemand zeigen, wie das Schlüsselwort environment
in Ansible funktioniert, vorzugsweise mit dem Codebeispiel, das ich oben angegeben habe?
Zumindest bei der aktuellen Version von Ansible funktioniert dieses Beispiel ** nicht **. Die Zeile 'executable =/bin/bash' muss in derselben Zeile wie' shell: ... 'stehen. Ich habe die Antwort entsprechend aktualisiert. –
Danke für die Korrektur :) – magnetik