0%

Ansible provides privilege escalation options to run commands with elevated privileges on target hosts. These options include:

  • --ask-become-pass or -K: Asks for the privilege escalation password.
  • --become-method: Specifies the privilege escalation method to use, such as sudo (default) or others listed in ansible-doc -t become -l.
  • --become-user: Runs operations as the specified user (default is root). This option is useful when you want to execute commands as a different user.
  • -b or --become: Runs operations with privilege escalation (does not imply password prompting).

Here are some examples:

Running a command without privilege escalation:

1
$ ansible -i inventory/hosts -m shell -a 'whoami' blacktemple

Running a command with privilege escalation (as root):

1
$ ansible -i inventory/hosts -b --ask-become-pass -m shell -a 'whoami' blacktemple

Running a command with privilege escalation using a sudoer without password prompt:

1
$ ansible -i inventory/hosts -b -m shell -a 'whoami' blacktemple

Running a command with privilege escalation as user “nginx”:

1
$ ansible -i inventory/hosts -b --become-user nginx -m shell -a 'whoami' blacktemple

N多年前,一个设计师选址的败笔,成就了世界建筑史上的奇观——比萨斜塔。曾经不能正常使用的建筑原有功能,在N多年后因飞来之笔而附加值大增,在旅游收入中名胜大噪,成为当地的支柱产业。于是大地对斜塔说,看看,不是我的地基的问题吧,我早就说过,如果是作为建筑的话,你早就淹没在哥特式、巴特式的建筑群中名不见经传了。

N+N年后,一个科学巨檠在比萨斜塔上玩康乐球,一不小心一个康乐球从手中滑脱,径直落下塔底,哇塞,科学史上的伟大定律诞生了!定格,闪光灯、镁光灯、碘钨灯闪烁,帅呆!斜塔也因此独获殊荣、大红大紫。

N+N+N年后,一群跛子入主斜塔,手里拿着铅球、康乐球、波波球、乒乓球,也试图诞生一个伟大的定律或别的什么哲理。或由于底子太薄,或由于悟性太差,没玩出什么高科技、高品位来,闲的无聊,改玩梭哈。你输我赢之间,难免东家长西家短、口舌是非多。

一日,跛子甲说,不知你们发现没有,这块宝地,是我有生以来走过的最平坦的一块福地?跛子乙说,纯粹胡说八道,这个地方是我走过的最崎岖的山路。争论未果,曲终人散。第二天跛子甲与跛子乙因先来后到的原因调换了座位,跛子甲说,今天运气真背,这块地方是我走过的最凹凸不平的糟糕之地。跛子乙说,你脑子又进水了,这块地方才真正是我走过的最幸福的康庄大道。

跛子,就是跛子。不会因穿上什么贵族的华丽霓裳,而变得贵族和有文化;也不会因为练就了拜仑的体魄,就具备了诗人的斗志和豪情;更不会因占据了什么福地、站在了巨人的肩膀上,就成就什么伟大的定律。

于是乎,斜塔对大地说,我是正的,你才是斜的。跛子说,梭哈不成,我们改玩麻将,看看谁笑到最后。

我们站在地平线,遥望曾经壮观的比萨斜塔,看着它一点点的倒下……