|
|
Basically username has the hostname as a variable.7 Y! T9 K6 j8 c6 W: X2 R
7 u6 n+ F( U+ t" P0 F; O( sNow our inventory has just IPs with group web.
0 \7 ]+ [9 o. ]+ B( Z8 d& H$ \* N/ w6 p! J1 E+ Q0 D* H
> cat inventory.txt
) d# }) k, F* Y$ C9 e[host]
8 W* b/ ]3 G& @. E2 L172.16.2.8- t! J/ T, z' |! I8 B7 Q4 L- O" d
172.16.x.y" ]& h2 z% B& x. j, l' H+ Z/ V
172.16.y.z
$ p- A4 K' s8 kMy playbook yml has ansible user as following.
2 v0 b1 S" U% I$ G5 l$ e
# j+ p, F7 D: N> cat uptime.yml
7 o" k) n: }% v9 ?- hosts: host$ T' m9 b( c2 a& I2 {- q! ]
vars:! O7 g2 h; \6 i$ p5 q9 j
ansible_ssh_port: xxxx
% t# Q6 p) @$ |+ E ansible_user: bob~1234~{{inventory_hostname}}
0 ~! W. |) g0 p! c3 [+ ~ tasks:
8 w& n0 N% c F7 x, ] - name: Run uptime command
* t& F0 |# q6 K shell: uptime
. P" W! g- X0 A3 H3 g3 ?1 {! MHowever, when I use following ansible-playbook command, it gives error for incorrect username.: }" o/ i1 X- @" H# M
: z% b, k: `7 i8 I6 W
> ansible-playbook -v uptime.yml -i inventory.txt --private-key=key.pem# S9 n' k7 Q0 U5 I
Please help me find correct ansible_user in playbook which has hostname as a variable inside.
* n( J: v4 e- H8 O5 k- u: }: X1 G& E: g# v2 [4 V' M/ f1 R
|
|