找回密码
 注册
查看: 12|回复: 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.
+ 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; _* @
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-12 04:10 , Processed in 0.017285 second(s), 23 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

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