Ausführen einer anzeigbaren lokalen Aufgabe in einem Remote-Playbook
Ich versuche, diese Aufgabe lokal auszuführen (auf dem Computer, auf dem das Playbook ausgeführt wird):
- name: get the local repo's branch name
local_action: git branch | awk '/^\*/{print $2}'
register: branchName
Ich habe viele Variationen ohne Erfolg ausprobiert
Alle anderen Aufgaben sollen auf dem Zielhost ausgeführt werden. Aus diesem Grund ist das Ausführen des gesamten lokalen Playbooks keine Option
TASK: [get the local repo's branch name] **************************************
<127.0.0.1> REMOTE_MODULE git branch | awk '/^\*/{print $2}'
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172 && chmod a+rx $HOME/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172 && echo $HOME/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172']
<127.0.0.1> PUT /tmp/tmpQVocvw TO /home/max/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172/git
<127.0.0.1> EXEC ['/bin/sh', '-c', '/usr/bin/python /home/max/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172/git; rm -rf /home/max/.ansible/tmp/ansible-tmp-1407258765.57-75899426008172/ >/dev/null 2>&1']
failed: [portal-dev] => {"failed": true}
msg: this module requires key=value arguments (['branch', '|', 'awk', '/^\\*/{print $2}'])
FATAL: all hosts have already failed -- aborting
aktualisieren:Ich bin dem Vorschlag von bkan gefolgt (siehe unten) und bin ein bisschen weiter gekommen, aber
- name: get the local repo's branch name
local_action: command git branch | (awk '/^\*/{print $2}')
sudo: no
register: branchName
Jetzt wird der Befehl git gestartet, aber nicht korrekt (siehe Fehler unten).
Beachten Sie, dass dieser Befehl perfekt als "Shell" ausgeführt wird, aber leider gibt es kein local_shell-Äquivalent zu local_action ...
failed: [portal-dev] => {"changed": true, "cmd": ["git", "branch", "|", "(awk", "/^\\*/{print $2})"], "delta": "0:00:00.002980", "end": "2014-08-05 18:00:01.293632", "rc": 129, "start": "2014-08-05 18:00:01.290652"}
stderr: usage: git branch [options] [-r | -a] [--merged | --no-merged]
or: git branch [options] [-l] [-f] <branchname> [<start-point>]
or: git branch [options] [-r] (-d | -D) <branchname>...
or: git branch [options] (-m | -M) [<oldbranch>] <newbranch>
...