|
|
Basically username has the hostname as a variable.
: b0 w+ D+ c8 n0 v! _* u6 G1 Q" ^7 q5 @0 S& R
Now our inventory has just IPs with group web.
- ^( Y5 Y: e q7 U h4 O9 g- c- [) R, P1 t
> cat inventory.txt' ~: K% W; b- W4 u: e
[host]+ Y! P7 @% D! j8 @
172.16.2.81 O- b0 e! p9 ^. H. }# O1 S
172.16.x.y! t, I& q( A+ z- E) x
172.16.y.z
$ B5 M% _9 Q7 cMy playbook yml has ansible user as following.
1 t' k% K8 f0 ]6 G1 {; H& F$ _, M; U. a7 P3 R
> cat uptime.yml' }0 v" ~2 R6 }# {5 O
- hosts: host6 o1 z: V/ d$ P+ r6 L0 s* u, S
vars:
$ q& J1 Q3 X! H! P ansible_ssh_port: xxxx# m0 v8 C! b+ |* e I4 b
ansible_user: bob~1234~{{inventory_hostname}}
3 T1 @- x- f) c! f tasks:' w# w3 ^ v; Z% F1 |3 `
- name: Run uptime command) K% D; D6 G! \" z) C. I) H0 y7 W
shell: uptime2 W$ d4 x+ L- G7 Z: c( O4 B; C2 E
However, when I use following ansible-playbook command, it gives error for incorrect username.
& c7 H7 _7 l8 q r' @8 k* |* e/ @, A9 Z; j
> ansible-playbook -v uptime.yml -i inventory.txt --private-key=key.pem
# g2 t! j5 E e' d% }6 ~Please help me find correct ansible_user in playbook which has hostname as a variable inside.
3 f3 }, S. o7 v4 O: W; h. e: ^) b: R9 a$ ~
|
|