Dynamically access instances unable to change the login user from root to centos

538 views
Skip to first unread message

Jeffrey Brewster

unread,
Feb 22, 2017, 1:08:30 PM2/22/17
to Ansible Project
Hi all, 


I'm able to add the host dynamically however I'm not able to run  yum install commands on it because of user issues: 


Error: 

command scp -v -t 'Please login as the user:



----

<10.133.180.62> SSH: EXEC sshpass -d14 scp -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/home/jbrewster/.ansible/cp/ansible-ssh-%h-%p-%r /tmp/tmpZYJT7h '[10.133.180.62]:'"'"'Please login as the user "centos" rather than the user "root"./setup.py'"'"''
 [WARNING]: scp transfer mechanism failed on [10.133.180.62]. Use ANSIBLE_DEBUG=1 to see detailed information

-----



Host creation successful: 
 

------------------------------------------



   - name: Add CentOS Instance to Inventory
      add_host: name=myserver7 groups=webservers
             ansible_ssh_host={{ myserver7.server.public_v4 }}
 
 - hosts: myserver7 
   remote_user: centos   
   sudo: yes   
   #become: 
   tasks:
    - debug:
         var: vars
    - name: ensure apache is at the latest version
      yum: name=httpd state=latest
    - name: make sure apache is running
      service: name=httpd state=running
-----------------------------------------------


The above is  what generates the failures. 



-----

full play book: 


---
 - name: Test
   hosts: localhost
   tasks:
    - os_server:
        cloud: testing
        name: myserver7
        state: present
        image: centos7
        nics:
          - net-name: vlan1180-dmz-ops
        flavor: m1.small
        key_name: jeff-desktop
        meta: 
         hostname: mysever7.localdomain
      register: myserver7
    - debug:
        var: myserver7

    - command: >
        ssh -o BatchMode=yes
        centos@{{myserver7.server.public_v4}} true
      register: result
      until: result|success
      retries: 300
      delay: 5 


    - name: Add CentOS Instance to Inventory
      add_host: name=myserver7 groups=webservers
             ansible_ssh_host={{ myserver7.server.public_v4 }}


  
 - hosts: myserver7 
   remote_user: centos   
   sudo: yes   
   #become: 
   tasks:
    - debug:
         var: vars
    - name: ensure apache is at the latest version
      yum: name=httpd state=latest
    - name: make sure apache is running
      service: name=httpd state=running


full error: 


TASK [setup] *******************************************************************
Using module file /usr/lib/python2.7/site-packages/ansible/modules/core/system/setup.py
<10.133.180.62> ESTABLISH SSH CONNECTION FOR USER: root
<10.133.180.62> SSH: EXEC sshpass -d14 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/home/jbrewster/.ansible/cp/ansible-ssh-%h-%p-%r 10.133.180.62 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo ~/.ansible/tmp/ansible-tmp-1487709168.28-100153560564195 `" && echo ansible-tmp-1487709168.28-100153560564195="` echo ~/.ansible/tmp/ansible-tmp-1487709168.28-100153560564195 `" ) && sleep 0'"'"''
<10.133.180.62> PUT /tmp/tmpqeBJEA TO Please login as the user "centos" rather than the user "root"./setup.py
<10.133.180.62> SSH: EXEC sshpass -d14 sftp -o BatchMode=no -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/home/jbrewster/.ansible/cp/ansible-ssh-%h-%p-%r '[10.133.180.62]'
 [WARNING]: sftp transfer mechanism failed on [10.133.180.62]. Use ANSIBLE_DEBUG=1 to see detailed information

<10.133.180.62> SSH: EXEC sshpass -d14 scp -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o User=root -o ConnectTimeout=10 -o ControlPath=/home/jbrewster/.ansible/cp/ansible-ssh-%h-%p-%r /tmp/tmpqeBJEA '[10.133.180.62]:'"'"'Please login as the user "centos" rather than the user "root"./setup.py'"'"''
 [WARNING]: scp transfer mechanism failed on [10.133.180.62]. Use ANSIBLE_DEBUG=1 to see detailed information

fatal: [myserver7]: FAILED! => {
    "failed": true, 
    "msg": "failed to transfer file to Please login as the user \"centos\" rather than the user \"root\"./setup.py:\n\nExecuting: program /usr/bin/ssh host 10.133.180.62, user (unspecified), command scp -v -t 'Please login as the user \"centos\" rather than the user \"root\"./setup.py'\nOpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 56: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 9101\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 3\r\nPlease login as the user \"centos\" rather than the user \"root\".\ndebug2: Exiting on signal 1\r\n"
}
to retry, use: --limit @/home/jbrewster/dev/ansible/anslaunch.retry

PLAY RECAP *********************************************************************
localhost                  : ok=5    changed=3    unreachable=0    failed=0   
myserver7                  : ok=0    changed=0    unreachable=0    failed=1   

[jbrewster@mojojojo ansible]$ 


Jeffrey Brewster

unread,
Feb 23, 2017, 3:33:53 PM2/23/17
to Ansible Project
Looking at this  it is most likely an issue with remote_user
Reply all
Reply to author
Forward
0 new messages