2014-03-31 11 views
6

Ziel: Angesichts eines Debian-Servers ohne installiertes Python (und einiger anderer fehlender ansible-Voraussetzungen) benutze ansible, um sie zu installieren, damit ich dann die normalen ansible-Module verwenden kann (fast alle erfordern Python), um den Server bereitzustellen.Bootstrapping ansible Voraussetzungen mit dem Script-Modul. Python benötigt?

Nach the ansible documentation for the "script" module „Dieses Modul benötigt keinen Python auf dem Remote-System, ähnlich wie die Rohmodul.“. Allerdings basiert auf meinen Tests scheint es wie das Skriptmodul Versuch in der Tat Python auf dem Remote-System, zumindest wenn die sudo Option wahr ist, ausgeführt werden. Ich glaube, ich kann bekommen so lange wie mit dem Skriptmodul zu arbeiten, wie ich nicht aktivieren sudo Option des ansible, aber dann muss ich meine Remote-Benutzer sudo Erlaubnis ohne Passwortabfrage haben oder mein Skript ist nur für interaktive Warte gehen zu hängen Eingabe des sudo-Passwortes

Also meine Frage ist: A) Was ist der Deal mit dem „Script“ -Modul ist. Benötigt es Python auf dem Remote-System oder nicht?

und B) Gibt es einen besseren Weg, um mein größeres Ziel zu erreichen, die Bereitstellung vollständig ohne manuelle Schritte vor ansible automatisierte selbst verwendet werden kann?

Hier ist meine Ausgabe von ansible-playbook -vvv, die zeigt, es läuft /usr/bin/python auf dem Remote-System, und es gibt keine Datei dort, weil Python noch nicht installiert ist.

TASK: [install ansible prerequisites] 
***************************************** <10.9.8.31> ESTABLISH 
CONNECTION FOR USER: plyons <10.9.8.31> EXEC ['ssh', '-C', '-tt', 
'-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', 
'-o', 'ControlPath=/Users/plyons/.ansible/cp/ansible- 
ssh-%h-%p-%r', '-o', 'StrictHostKeyChecking=no', '-o', 
'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications 
=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 
'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', 
'10.9.8.31', "/bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible- 
tmp-1396233547.35-182235573044157 && chmod a+rx $HOME/.ansible/tmp 
/ansible-tmp-1396233547.35-182235573044157 && echo 
$HOME/.ansible/tmp/ansible-tmp-1396233547.35-182235573044157'"] 
<10.9.8.31> PUT 
/var/folders/n4/8skjkv9s5hbc4t5r0tr0xrk80000gn/T/tmpT1Vh6e TO 
/home/plyons/.ansible/tmp/ansible- 
tmp-1396233547.35-182235573044157/stat <10.9.8.31> EXEC ['ssh', 
'-C', '-tt', '-q', '-o', 'ControlMaster=auto', '-o', 
'ControlPersist=60s', '-o', 'ControlPath=/Users/plyons/.ansible/cp 
/ansible-ssh-%h-%p-%r', '-o', 'StrictHostKeyChecking=no', '-o', 
'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications 
=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 
'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', 
'10.9.8.31', '/bin/sh -c \'sudo -k && sudo -H -S -p "[sudo via 
ansible, key=hyplatqjmvybpfqtukjegkibbuyrnoqj] password: " -u root 
/bin/sh -c \'"\'"\'echo SUDO-SUCCESS- 
hyplatqjmvybpfqtukjegkibbuyrnoqj; /usr/bin/python 
/home/plyons/.ansible/tmp/ansible- 
tmp-1396233547.35-182235573044157/stat\'"\'"\'\''] 

Hier ist mein Textbuch Aufgabe:

tasks: 
    - 
    name: install ansible prerequisites 
    script: ansible_prereqs.sh creates=/root/.ansible_prereqs_installed 

Und das ansible_prereqs.sh Skript:

#!/bin/sh 
#install ansible prereqs manually or all apt-based ansible commands will fail 
# http://euphonious-intuition.com/2013/01/bootstrapping-a-cluster-with-ansible-debian-6-and-oracle-java-7/ 
apt-get update 
apt-get install -y python python-apt python-pycurl sshpass 
touch /root/.ansible_prereqs_installed 

Antwort

8

roh und Skripte erfordern nicht Python. Ich denke, die Erstellungen erfordern Python. Um zu überprüfen, Sie

ansible -m script -a "ansible_prereqs.sh" 10.9.8.31 -vvvv 

ausführen können, was Sie tun können, ist, verschiebt sich die Funktion auf Ihr Skript erstellt

#!/bin/sh 
#install ansible prereqs manually or all apt-based ansible commands will fail 
# http://euphonious-intuition.com/2013/01/bootstrapping-a-cluster-with-ansible-debian-6-and-oracle-java-7/ 
if [ ! -f /root/.ansible_prereqs_installed ]; then 
     apt-get update 
     apt-get install -y python python-apt python-pycurl sshpass 
     touch /root/.ansible_prereqs_installed 
     echo "CHANGE" 
fi 

Und Sie können Ihre Textbuch so etwas wie dieses

tasks: 
    - 
    name: install ansible prerequisites 
    script: ansible_prereqs.sh creates=/root/.ansible_prereqs_installed 
    register: ans_preq 
    changed_when: "'CHANGE' in ans_preq.stdout" 

Hoffnung haben, das hilft

+0

Dies hilft. Die Zeile 'changed_when' scheint ungültig zu sein. YAML und ansible zeigen einen Syntaxfehler bezüglich der Anführungszeichen. –

+0

Ich änderte die Zitate sollten funktionieren – DomaNitro

+1

Register fehlte ein Doppelpunkt und dies machte die changed_when aussehen wie das Problem - jetzt behoben. –

10

OK, weitere Tests führen mich zu verstehen, dass @DomaNitro ist richtig, dass es ist nicht das script Modul selbst per-sagen, dass Python erfordert, aber die creates Option insbesondere, weil das ein stat Python-Skript verwendet.

jedoch immer noch Dinge erscheinen, weil in der Anfangsprüfung für die creates Marker-Datei zu funktionieren, wird ansible tun: /usr/bin/python /home/plyons/.ansible/tmp/ansible-tmp-1396271950.37-134911276396535/stat, die fehl, weil /usr/bin/python nicht vorhanden ist, aber das ist in Ordnung, weil wir das Skript wollen sowieso laufen.

Sobald mein ansible_prereqs.sh Skript ausgeführt wird, wird stat Moduls ansible anfangen zu arbeiten, weil /usr/bin/python jetzt installiert ist, so dass nachfolgende Wiederholungen werden die Marker-Datei vorhanden ist und umgehen das Skript zu sehen.

Also brauche ich nicht die creates Logik in meinem Shell-Skript-Code zu implementieren. Hier ist meine letzte Arbeitstextbuch:

--- 
- 
    hosts: all 
    gather_facts: no 
    sudo: yes 
    tasks: 
    - 
     name: install ansible prerequisites 
     script: ansible_prereqs.sh creates=/root/.ansible_prereqs_installed 

Und hier ist das Skript es ansible_prereqs.sh läuft:

#!/bin/bash 
set -e 
apt-get -qq update 
apt-get -qq --yes install python python-apt python-pycurl sshpass 
touch /root/.ansible_prereqs_installed 

Hier einige ansible-playbook -vvv Ausgabe mit Erläuterungen hinzugefügt.

<10.9.8.31> ESTABLISH CONNECTION FOR USER: plyons 

#Not sure exactly what this does, but presumably some basic 
#bootstrap sanity checking 
<10.9.8.31> EXEC ['ssh', '-C', '-tt', 
'-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 
'ControlPath=/Users/plyons/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 
'StrictHostKeyChecking=no', '-o', 'KbdInteractiveAuthentication=no', 
'-o', 'PreferredAuthentications=gssapi-with-mic,gssapi- 
keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 
'ConnectTimeout=10', '10.9.8.31', "/bin/sh -c 'mkdir -p 
$HOME/.ansible/tmp/ansible-tmp-1396273094.39-170062058638174 && chmod 
a+rx $HOME/.ansible/tmp/ansible-tmp-1396273094.39-170062058638174 && 
echo $HOME/.ansible/tmp/ansible-tmp-1396273094.39-170062058638174'"] 

#OK the "creates" option causes ansible to upload the "stat" 
#python program 
<10.9.8.31> PUT 
/var/folders/n4/8skjkv9s5hbc4t5r0tr0xrk80000gn/T/tmp5CVz6i TO 
/home/plyons/.ansible/tmp/ansible- 
tmp-1396273094.39-170062058638174/stat 

#Then ansible attempts to run it with /usr/bin/python 
#This fails but ansible seems to proceed anyway, which is OK 
<10.9.8.31> EXEC ['ssh', '-C', '-tt', '-q', '-o', 'ControlMaster=auto', '-o', 
'ControlPersist=60s', '-o', 'ControlPath=/Users/plyons/.ansible/cp 
/ansible-ssh-%h-%p-%r', '-o', 'StrictHostKeyChecking=no', '-o', 
'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications 
=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 
'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', '10.9.8.31', 
'/bin/sh -c \'sudo -k && sudo -H -S -p "[sudo via ansible, 
key=llljvkxiztigvqonzohgzwwekusxtprk] password: " -u root /bin/sh -c 
\'"\'"\'echo SUDO-SUCCESS-llljvkxiztigvqonzohgzwwekusxtprk; 
/usr/bin/python /home/plyons/.ansible/tmp/ansible- 
tmp-1396273094.39-170062058638174/stat\'"\'"\'\''] 

#Now ansible uploads my script 
<10.9.8.31> PUT 
/Users/plyons/projects/redacted/deploy/ansible_prereqs.sh 
TO /home/plyons/.ansible/tmp/ansible-tmp-1396273094.39-170062058638174/ansible_prereqs.sh 

#Then it marks it executable 
<10.9.8.31> EXEC ['ssh', '-C', 
'-tt', '-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', 
'-o', 'ControlPath=/Users/plyons/.ansible/cp/ansible-ssh-%h-%p-%r', 
'-o', 'StrictHostKeyChecking=no', '-o', 
'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications 
=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 
'PasswordAuthentication=no', '-o', 'ConnectTimeout=10', '10.9.8.31', 
u'/bin/sh -c \'sudo -k && sudo -H -S -p "[sudo via ansible, 
key=cgmwlvtjoxuighdqujwmmpvioiumveac] password: " -u root /bin/sh -c 
\'"\'"\'echo SUDO-SUCCESS-cgmwlvtjoxuighdqujwmmpvioiumveac; chmod +rx 
/home/plyons/.ansible/tmp/ansible- 
tmp-1396273094.39-170062058638174/ansible_prereqs.sh\'"\'"\'\''] 

#Then it runs it 
<10.9.8.31> EXEC ['ssh', '-C', '-tt', '-q', '-o', 
'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 
'ControlPath=/Users/plyons/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 
'StrictHostKeyChecking=no', '-o', 'KbdInteractiveAuthentication=no', 
'-o', 'PreferredAuthentications=gssapi-with-mic,gssapi- 
keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 
'ConnectTimeout=10', '10.9.8.31', u'/bin/sh -c \'sudo -k && sudo -H -S 
-p "[sudo via ansible, key=cqqswbszbeabpclraxsxwzzatbolgmgf] password: 
" -u root $SHELL -c \'"\'"\'echo SUDO-SUCCESS- 
cqqswbszbeabpclraxsxwzzatbolgmgf; /home/plyons/.ansible/tmp/ansible- 
tmp-1396273094.39-170062058638174/ansible_prereqs.sh \'"\'"\'\''] 

#Then it deletes it 
<10.9.8.31> EXEC ['ssh', '-C', '-tt', 
'-q', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 
'ControlPath=/Users/plyons/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 
'StrictHostKeyChecking=no', '-o', 'KbdInteractiveAuthentication=no', 
'-o', 'PreferredAuthentications=gssapi-with-mic,gssapi- 
keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 
'ConnectTimeout=10', '10.9.8.31', "/bin/sh -c 'rm -rf 
/home/plyons/.ansible/tmp/ansible-tmp-1396273094.39-170062058638174/ 
>/dev/null 2>&1'"] 
+0

danke für diesen letzten Beitrag. Jetzt weiß ich was ich morgen machen soll ;-) – ThorstenS

Verwandte Themen