|
|
Basically username has the hostname as a variable.
+ i( J7 i$ X" s0 p7 H1 X# }4 _
& z; b4 d- p' L) E0 ]; E6 A/ VNow our inventory has just IPs with group web.7 y% Y' K# p$ ?8 |2 F* c
! `/ z9 q6 g* G2 o+ Q> cat inventory.txt' a$ n% `' W) W2 ^" N# }
[host]. r% y) @* k, p5 |5 K, \
172.16.2.85 z, M! B( K) `* s# Y+ d
172.16.x.y, U7 \# P3 g7 V3 A5 `
172.16.y.z
3 y) I& H& B) t: ^My playbook yml has ansible user as following.$ G5 e/ R* P; |' o. S. q* S
& R5 ^; I4 b7 {1 d! q4 L
> cat uptime.yml
: O. H2 p* }& p/ k& m5 l- hosts: host+ c2 d9 v6 A3 F, d6 P" s) ^. P
vars:4 b" X5 V1 e% N7 x2 y' L! M
ansible_ssh_port: xxxx& Q: M4 c2 `; K3 O# n0 b& O4 @+ c" W3 n
ansible_user: bob~1234~{{inventory_hostname}}
4 W0 o' g0 P3 z- [. S; v tasks:* q& L" y' n) ^* l4 K
- name: Run uptime command& m( p6 x; C+ W }( I
shell: uptime
7 O, L+ ?* L& }6 D+ E# {However, when I use following ansible-playbook command, it gives error for incorrect username.
6 Y' a- @* X0 e+ P1 k: ^3 ?- H# Q- I; C8 P: b6 _1 `: b
> ansible-playbook -v uptime.yml -i inventory.txt --private-key=key.pem4 ^# d6 ]1 q# |4 V; p o8 f
Please help me find correct ansible_user in playbook which has hostname as a variable inside.) [0 L6 k9 q$ m/ Z
3 D* w) y; _* @ |
|