Ansible get the username from the command line -
in playbooks reference username (exclusively "ubuntu") lot.
is there built in way "get value passed in command line"?
i know can do
ansible-playbook <task> -u <user> -k --extra-vars "user=<user>" and can use {{user}} in playbook, feels odd defining user twice.
as woodham stated, ansible variable represents connecting user is
{{ ansible_user }} (ansible < 2.0 {{ ansible_ssh_user }} ) but don't have define in inventory file per se.
you can define in:
1. play, if use ansible-playbook: see manual on playbooks
- name: play hosts: remote_user: ubuntu 2. in inventory file: see manual on inventory
[all] other1.example.com ansible_user=ubuntu (ansible < 2.0 ansible_ssh_user) 3. stated, on commandline:
ansible-playbook -i inventory -u ubuntu playbook.yml 4. ansible config file remote_user directive. see manual on config file
the ansible config file can placed in current folder ansible.cfg, homedir .ansible.cfg or /etc/ansible/ansbile.cfg.
[defaults] remote_user=ubuntu
Comments
Post a Comment