tgcloud
tgcloud

Reputation: 887

Ansible: SSH Error with ansible

I am deploying stack on host A and I want to execute post configuration scripts on host B. Those script should be pushed from ansible controller(host C) or from host A to host B.

To achieve this I created a test play-book.

- 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

I am trying both the approach using "when" and getting same error.

Inventory file has two host, both are segregated in different groups.

[controller]
10.17.10.150    ansible_ssh_user=hyroot

[monservers]
10.17.10.85     ansible_ssh_user=ubuntu

I am getting below error while running the playbook, at the same time I am able to ssh passwordless, both the host manually.

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

Also I noticed in log that ansible skipping is execution of python script on 10.17.10.150 .

I want ansible to execute python script on 10.17.10.85, and not the 10.17.10.150.

Upvotes: 1

Views: 1211

Answers (1)

tgcloud
tgcloud

Reputation: 887

I found the answer..! sudo_exe = su myuser was enabled in ansible.cfg file!

Upvotes: 1

Related Questions