找回密码
 注册
查看: 10|回复: 0

ansible playbook方式使用yml文件方式配置ansible通信port以及user

[复制链接]

1

主题

0

回帖

12

积分

管理员

积分
12
QQ
发表于 2024-4-11 10:31:29 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

返回首页|Archiver|手机版|小黑屋|易陆发现技术论坛 ( 蜀ICP备2026014127号-1 )

GMT+8, 2026-6-12 02:00 , Processed in 0.015572 second(s), 23 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表