Ansible不会在远程服务器上执行命令

时间:2016-08-30 04:13:40

标签: ansible ansible-2.x

我在OS X" El capitan"上使用由pip操纵的 Ansible 2.1.1.0 。 我尝试了一个非常简单的配置:

getExplorerPageData(): Observable<IExplorerPageData> {
  return this.http.get(this.baseurl + "/explorerpagedata")
  .map((response: Response) => <IExplorerPageData>response.json())
  .catch(this.handleError);
}

getTag(id: number): ITag {
    //todo need to return one of the tags in explorerPageData.Tags
    return 
};

export interface IExplorerPageData{
 Tags: ITag[],
 Uploads: IUpload[],
}

export interface ITag {
  TagId: number,
  Title: string
}

使用变量 ansible_user 通过ssh使用相应的公钥进行连接:

#/etc/ansible/hosts
[webservers]
my.remote.server

当我尝试ping服务器#/etc/ansible/group_vars/webservers --- ansible_user: my_user 时,似乎一切正常:

ansible webservers -m ping

尽管如此,当我尝试在远程服务器上运行任何命令时,它会在我的本地计算机上执行,例如,运行my.remote.server | SUCCESS => { "changed": false, "ping": "pong" } 应显示 my.remote.server ,但会显示此信息:

ansible webservers -m shell -a "echo $HOSTNAME"

知道可能导致这个问题的原因吗?

1 个答案:

答案 0 :(得分:6)

That's because "echo $HOSTNAME" is being evaluated in your local shell before being passed to the remote server over SSH. Try this:

ansible webservers -a hostname

Or this:

ansible webservers -m shell -a 'echo $HOSTNAME'