2016-05-18 20 views
0

Ich bin bereit, Stack auf Host A zu implementieren und ich möchte Postkonfigurationsskripten auf Host B ausführen. Diese Skript sollte von ansible Controller (Host C) oder von Host A an Host B.Ansible: SSH Fehler mit ansible

geschoben werden

Um dies zu erreichen, habe ich ein Testspielbuch erstellt.

- hosts: all 
    tasks: 
    - name: Executin python script 
     shell: /usr/bin/python test.py 
#  when: "'10.17.10.85' in groups['monserver']" 
     when: "'monserver' in {{ group_names }}" 
     register: test 
    - debug: test.stdout 

Ich versuche sowohl den Ansatz mit "wenn" und den gleichen Fehler zu bekommen.

Inventardatei hat zwei Hosts, beide sind in verschiedenen Gruppen getrennt.

[controller] 
10.17.10.150 ansible_ssh_user=hyroot 

[monservers] 
10.17.10.85  ansible_ssh_user=ubuntu 

ich unten Störung erhalten, während das Textbuch ausgeführt wird, zur gleichen Zeit ich in der Lage bin ssh ohne Passwort, den Host manuell.

PLAY [all] ******************************************************************** 

GATHERING FACTS *************************************************************** 
<10.17.10.150> ESTABLISH CONNECTION FOR USER: hyroot 
<10.17.10.85> ESTABLISH CONNECTION FOR USER: ubuntu 
<10.17.10.150> REMOTE_MODULE setup 
<10.17.10.85> REMOTE_MODULE setup 
<10.17.10.150> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=hyroot', '-o', 'ConnectTimeout=10', '10.17.10.150', "/bin/sh -c 'mkdir -p /tmp/ansible-tmp-1463545052.75-6584687306251 && chmod a+rx /tmp/ansible-tmp-1463545052.75-6584687306251 && echo /tmp/ansible-tmp-1463545052.75-6584687306251'"] 
<10.17.10.85> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ubuntu', '-o', 'ConnectTimeout=10', '10.17.10.85', "/bin/sh -c 'mkdir -p /tmp/ansible-tmp-1463545052.75-48027114165698 && chmod a+rx /tmp/ansible-tmp-1463545052.75-48027114165698 && echo /tmp/ansible-tmp-1463545052.75-48027114165698'"] 
<10.17.10.150> PUT /tmp/tmpfmKMrv TO /tmp/ansible-tmp-1463545052.75-6584687306251/setup 
<10.17.10.150> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=hyroot', '-o', 'ConnectTimeout=10', '10.17.10.150', "/bin/sh -c 'chmod a+r /tmp/ansible-tmp-1463545052.75-6584687306251/setup'"] 
<10.17.10.150> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=hyroot', '-o', 'ConnectTimeout=10', '10.17.10.150', u"/bin/sh -c 'LANG=C LC_CTYPE=C /usr/bin/python /tmp/ansible-tmp-1463545052.75-6584687306251/setup; rm -rf /tmp/ansible-tmp-1463545052.75-6584687306251/ >/dev/null 2>&1'"] 
<10.17.10.85> PUT /tmp/tmpYPmXeY TO /tmp/ansible-tmp-1463545052.75-48027114165698/setup 
<10.17.10.85> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ubuntu', '-o', 'ConnectTimeout=10', '10.17.10.85', "/bin/sh -c 'chmod a+r /tmp/ansible-tmp-1463545052.75-48027114165698/setup'"] 
<10.17.10.85> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ubuntu', '-o', 'ConnectTimeout=10', '10.17.10.85', u'/bin/sh -c \'su hyroot -k && su hyroot -H -S -p "[sudo via ansible, key=tponxjlokfvzaswnynqyxdejohcambhm] password: " -u hyroot /bin/sh -c \'"\'"\'echo SUDO-SUCCESS-tponxjlokfvzaswnynqyxdejohcambhm; LANG=C LC_CTYPE=C /usr/bin/python /tmp/ansible-tmp-1463545052.75-48027114165698/setup; rm -rf /tmp/ansible-tmp-1463545052.75-48027114165698/ >/dev/null 2>&1\'"\'"\'\''] 
<10.17.10.85> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=ubuntu', '-o', 'ConnectTimeout=10', '10.17.10.85', "/bin/sh -c 'rm -rf /tmp/ansible-tmp-1463545052.75-48027114165698/ >/dev/null 2>&1'"] 
failed: [10.17.10.85] => {"failed": true, "parsed": false} 
invalid output was: su: invalid option -- 'k' 

Usage: 
su [options] [-] [USER [arg]...] 

Change the effective user id and group id to that of USER. 
A mere - implies -l. If USER not given, assume root. 

Options: 
-m, -p, --preserve-environment do not reset environment variables 
-g, --group <group>    specify the primary group 
-G, --supp-group <group>  specify a supplemental group 

-, -l, --login     make the shell a login shell 
-c, --command <command>   pass a single command to the shell with -c 
--session-command <command>  pass a single command to the shell with -c 
           and do not create a new session 
-f, --fast      pass -f to the shell (for csh or tcsh) 
-s, --shell <shell>    run shell if /etc/shells allows it 

-h, --help  display this help and exit 
-V, --version output version information and exit 

For more details see su(1). 
OpenSSH_6.7p1 Debian-5, OpenSSL 1.0.1k 8 Jan 2015 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: /etc/ssh/ssh_config line 19: Applying options for * 
debug1: auto-mux: Trying existing master 
debug2: fd 3 setting O_NONBLOCK 
debug2: mux_client_hello_exchange: master version 4 
debug3: mux_client_forwards: request forwardings: 0 local, 0 remote 
debug3: mux_client_request_session: entering 
debug3: mux_client_request_alive: entering 
debug3: mux_client_request_alive: done pid = 29670 
debug3: mux_client_request_session: session request sent 
debug1: mux_client_request_session: master session id: 2 
debug3: mux_client_read_packet: read header failed: Broken pipe 
debug2: Received exit status from master 1 
Shared connection to 10.17.10.85 closed. 

<10.17.10.150> EXEC ['ssh', '-C', '-tt', '-vvv', '-o', 'ControlMaster=auto', '-o', 'ControlPersist=60s', '-o', 'ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r', '-o', 'KbdInteractiveAuthentication=no', '-o', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', '-o', 'PasswordAuthentication=no', '-o', 'User=hyroot', '-o', 'ConnectTimeout=10', '10.17.10.150', "/bin/sh -c 'rm -rf /tmp/ansible-tmp-1463545052.75-6584687306251/ >/dev/null 2>&1'"] 
ok: [10.17.10.150] 

TASK: [Executin python script] ************************************************ 
skipping: [10.17.10.150] 

TASK: [debug icinga_stdout] *************************************************** 
<10.17.10.150> ESTABLISH CONNECTION FOR USER: hyroot 
ok: [10.17.10.150] => { 
    "msg": "Hello world!" 
} 

PLAY RECAP ******************************************************************** 
      to retry, use: --limit @/root/pytask.retry 

10.17.10.150    : ok=2 changed=0 unreachable=0 failed=0 
10.17.10.85    : ok=0 changed=0 unreachable=0 failed=1 

Auch bemerkte ich in log, dass ansible Skipping auf 10.17.10.150 Ausführung von Python-Skript ist.

Ich möchte ansible Python-Skript auf 10.17.10.85, und nicht die 10.17.10.150 ausführen.

Antwort

0

Ich fand die Antwort ..! sudo_exe = su myuser wurde in der Datei ansible.cfg aktiviert!