[ English | English (United Kingdom) | Indonesia | Deutsch | русский | español ]

Lauf Ad-hoc Ansible spielt

Being familiar with running ad-hoc Ansible commands is helpful when operating your OpenStack-Ansible deployment. For a review, we can look at the structure of the following ansible command:

$ ansible example_group -m shell -a 'hostname'

This command calls on Ansible to run the example_group using the -m shell module with the -a argument which is the hostname command. You can substitute example_group for any groups you may have defined. For example, if you had compute_hosts in one group and infra_hosts in another, supply either group name and run the command. You can also use the * wild card if you only know the first part of the group name, for instance if you know the group name starts with compute you would use compute_h*. The -m argument is for module.

Modules can be used to control system resources or handle the execution of system commands. For more information about modules, see Module Index and About Modules.

If you need to run a particular command against a subset of a group, you could use the limit flag -l. For example, if a compute_hosts group contained compute1, compute2, compute3, and compute4, and you only needed to execute a command on compute1 and compute4 you could limit the command as follows:

$ ansible example_group -m shell -a 'hostname' -l compute1,compute4

Bemerkung

Jeder Host ist durch Kommas getrennt ohne Leerzeichen.

Bemerkung

Führen Sie die Ad-hoc-Ansible-Befehle aus dem Verzeichnis openstack-ansible/playbooks aus.

Weitere Informationen finden Sie unter Inventar und Muster.

Das Shell-Modul ausführen

Die zwei am häufigsten verwendeten Module sind die shell und copy-Module. Das shell-Modul übernimmt den Befehlsnamen, gefolgt von einer Liste von durch Leerzeichen getrennten Argumenten. Es ist fast wie das Befehlsmodul, aber führt den Befehl durch eine Shell (/bin/sh) auf dem Remote-Knoten.

Mit dem Shell-Modul können Sie beispielsweise den Speicherplatz auf einer Gruppe von Compute-Hosts prüfen:

$ ansible compute_hosts -m shell -a 'df -h'

So überprüfen Sie den Status Ihres Galera-Clusters:

$ ansible galera_container -m shell -a "mysql \
-e 'show status like \"%wsrep_cluster_%\";'"

Wenn ein Modul als ad-hoc Kommando verwendet wird, werden ein paar Parameter nicht benötigt. Zum Beispiel, für das chdir Kommando ist kein chdir=/home/user ls notwendig, wenn Ansible von CLI aufgerufen wird:

$ ansible compute_hosts -m shell -a 'ls -la /home/user'

Weitere Informationen finden Sie unter Shell - Befehle in Knoten ausführen.

Das Kopiermodul ausführen

The copy module copies a file on a local machine to remote locations. To copy files from remote locations to the local machine you would use the fetch module. If you need variable interpolation in copied files, use the template module. For more information, see copy - Copies files to remote locations.

Das folgende Beispiel zeigt, wie Sie eine Datei von Ihrem Deployment-Host in das Verzeichnis /tmp auf einer Gruppe entfernter Maschinen verschieben:

$ ansible remote_machines -m copy -a 'src=/root/FILE '\
'dest=/tmp/FILE'

The fetch module gathers files from remote machines and stores the files locally in a file tree, organized by the hostname from remote machines and stores them locally in a file tree, organized by hostname.

Bemerkung

Dieses Modul überträgt Protokolldateien, die möglicherweise nicht vorhanden sind, so dass eine fehlende Remote-Datei kein Fehler ist, es sei denn, fail_on_missing ist auf yes gesetzt.

Die folgenden Beispiele zeigen die Datei nova-compute.log, die von einem einzelnen Compute-Host abgerufen wird:

root@libertylab:/opt/rpc-openstack/openstack-ansible/playbooks# ansible compute_hosts -m fetch -a 'src=/var/log/nova/nova-compute.log dest=/tmp'
aio1 | success >> {
    "changed": true,
    "checksum": "865211db6285dca06829eb2215ee6a897416fe02",
    "dest": "/tmp/aio1/var/log/nova/nova-compute.log",
    "md5sum": "dbd52b5fd65ea23cb255d2617e36729c",
    "remote_checksum": "865211db6285dca06829eb2215ee6a897416fe02",
    "remote_md5sum": null
}

root@libertylab:/opt/rpc-openstack/openstack-ansible/playbooks# ls -la /tmp/aio1/var/log/nova/nova-compute.log
-rw-r--r-- 1 root root 2428624 Dec 15 01:23 /tmp/aio1/var/log/nova/nova-compute.log

Verwenden von Tags

Tags are similar to the limit flag for groups, except tags are used to only run specific tasks within a playbook. For more information on tags, see Tags and Understanding ansible tags.

Ansible Forks

Die Standardeinstellung für MaxSessions für den OpenSSH-Daemon ist 10. Jeder Ansible-Fork verwendet eine Sitzung. Standardmäßig legt Ansible die Anzahl der Forks auf 5 fest. Sie können jedoch die Anzahl der verwendeten Forks erhöhen, um die Bereitstellungsleistung in großen Umgebungen zu verbessern.

Beachten Sie, dass mehr als 10 Forks Probleme bei allen Playbooks verursachen, die delegate_to oder local_action in den Aufgaben verwenden. Es wird empfohlen, die Anzahl der Forks bei der Ausführung in der Steuerungsebene nicht zu erhöhen, da hier die Delegierung am häufigsten verwendet wird.

Die Anzahl der verwendeten Forks kann permanent geändert werden, indem die entsprechende Änderung an den ANSIBLE_FORKS in Ihrer Datei .bashrc vorgenommen wird. Alternativ kann es für eine bestimmte Playbook-Ausführung geändert werden, indem der CLI-Parameter --forks verwendet wird. Das folgende Beispiel führt das Nova-Playbook gegen die Kontrollebene mit 10 Forks und dann gegen die Rechenknoten mit 50 Forks aus.

# openstack-ansible --forks 10 os-nova-install.yml --limit compute_containers
# openstack-ansible --forks 50 os-nova-install.yml --limit compute_hosts

Weitere Informationen zu Forks finden Sie in den folgenden Referenzen: