访问remote_user变量 [英] Accessing remote_user variable

查看:82
本文介绍了访问remote_user变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎可行,但是它脆弱吗?我希望将文件命令中的所有者和组设置为someguy.我希望能够使用{{ remote_user }},但这是行不通的.

This seems to work, but is it fragile? I want the owner and group in the files command to be set to someguy. I'd expect to be able to use {{ remote_user }} but that doesn't work.

这是一个示例剧本,展示了我的意思.

This is an example playbook showing what I mean.

---
- hosts: foobar
  remote_user: someguy
  tasks:
    - name: configure /usr/src/foo
      file: 
        dest: /usr/src/foo
        state: directory
        owner: {{ ansible_ssh_user }}
        group: {{ ansible_ssh_user }}
        recurse: yes
      sudo: yes

这不起作用:

---
- hosts: foobar
  remote_user: someguy
  tasks:
    - name: configure /usr/src/foo
      file: 
        dest: /usr/src/foo
        state: directory
        owner: {{ remote_user }}
        group: {{ remote_user }}
        recurse: yes
      sudo: yes

一个或多个未定义变量:'remote_user'未定义

One or more undefined variables: 'remote_user' is undefined

推荐答案

还有{{ ansible_ssh_user }},它包含远程用户名,似乎可以正常访问. 另请参阅此答案.

There's also {{ ansible_ssh_user }}, which contains remote user name and seems to be accessible without issues. See also this answer.

这篇关于访问remote_user变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆