|
|
Basically username has the hostname as a variable.
w6 e; R. N7 t; J6 O
9 n4 C! M) ~1 ]7 p+ iNow our inventory has just IPs with group web.
7 i# j( e4 f3 f
7 i( W& |% |4 b4 o' t, G> cat inventory.txt5 ~ h, n; X0 Y
[host]
4 |- d7 C4 W7 J( g2 A$ H172.16.2.85 T( r* ~* S: L3 J0 _
172.16.x.y. H# |+ X( u Q+ l
172.16.y.z
" S" v7 W* S, R7 a/ C( jMy playbook yml has ansible user as following.
+ D% z$ Y2 K! p% }
& \1 _- t# _1 X; E4 I> cat uptime.yml
$ g& U% F- q3 N' z, V, S- hosts: host' `6 b3 J! |! o/ t* x
vars:1 q" k! P7 Q3 Q# a" I3 ]( {
ansible_ssh_port: xxxx8 D) a2 o# o- C& ?2 H
ansible_user: bob~1234~{{inventory_hostname}}: H6 m' z- u& b& ^
tasks:! f3 P9 p# u. x/ n% H
- name: Run uptime command, ^- d0 e: P( v6 Q/ J1 v S
shell: uptime, N' O6 [6 v5 L* o) n, O
However, when I use following ansible-playbook command, it gives error for incorrect username.8 L/ K5 ~% g% J+ @
! g! ^7 a% @+ y0 C( d1 a> ansible-playbook -v uptime.yml -i inventory.txt --private-key=key.pem
( l3 @. N' u) @& u) _4 q$ jPlease help me find correct ansible_user in playbook which has hostname as a variable inside.
& H6 j5 l' O8 P7 G9 _ g7 L; j
$ Z3 z) { }/ V# [1 I |
|