建立用户的SSH连接:在命令行上指定单个主机时无

时间:2016-01-26 21:43:31

标签: ansible

在命令行中指定单个主机时如何设置ssh或ansible_user?

当我指定单个主机时如下:

$ansible-playbook -i "ceph1," jdk.yml
TASK [hadoop : create hadoop group] ********************************************
task path: /playbooks/yarn/roles/hadoop/tasks/install.yml:2
<ceph1> ESTABLISH SSH CONNECTION FOR USER: None

ssh conneciton用户和{{ansible_user}}都没有,但我在ssh / config中定义了它

$cat jdk.yml
- hosts: all
  vars_files:
     - default.yml
  roles:
     - role: jdk

$cat role/jdk/tasks/main.yml

- name: set java home
  lineinfile: dest=/home/{{ ansible_ssh_user }}/.bashrc
              line={{ item }}
  with_items:
    - export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

$cat hosts
    ceph1 ansible_user=ubuntu

$cat ~/.ssh/config
    Host ceph1
    User ubuntu

当然runnig以下是好的

$ansible-playbook  jdk.yml

1 个答案:

答案 0 :(得分:0)

您可以传递-e参数:

# ansible -m ping web1 -i inventory/a2  -vvv -e "ansible_user=ceph"
<a2-web1> ESTABLISH SSH CONNECTION FOR USER: ceph