Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing remote_user variable

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

This doesn't work:

---
- 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

One or more undefined variables: 'remote_user' is undefined

like image 317
Joshua Grigonis Avatar asked Jun 01 '15 17:06

Joshua Grigonis


1 Answers

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

like image 50
iron77 Avatar answered Sep 26 '22 05:09

iron77