首页 > 其他分享 >ansible使用sudo权限执行命令

ansible使用sudo权限执行命令

时间:2024-01-17 20:47:16浏览次数:21  
标签:执行命令 Feb sudo etc ansible ssh 20 root

1.修改ansible配置文件
vim /etc/ansible/ansible.cfg
取消注释的行:
remote_tmp = ~/.ansible/tmp
inventory = /etc/ansible/hosts
host_key_checking = False

2.编写host文件
vim /etc/ansible/hosts
10.0.3.2 ansible_ssh_user="ydpower" ansible_ssh_port="5151" ansible_ssh_pass="Jvo0#e3f%nmhs-pp-mw003002" ansible_become_pass="Jvo0#e3f%nmhs-pp-mw003002"

3.客户端配置ydpower使用sudo的权限

4.执行ansible命令
[root@ydapp18 ansible]# ansible 10.0.3.2 -m shell -a 'ls -l /root/' -become=true
10.0.3.2 | SUCCESS | rc=0 >>
total 16
drwxr-xr-x. 2 root root 6 Feb 20 21:49 a
-rw-------. 1 root root 1727 Feb 2 21:30 anaconda-ks.cfg
-rwxr-xr-x. 1 root root 11448 Feb 20 23:07 config_centos73.sh
drwxr-x--- 2 root root 6 Mar 5 20:59 test
————————————————
版权声明:本文为CSDN博主「运维那些事」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42789427/article/details/114414474

标签:执行命令,Feb,sudo,etc,ansible,ssh,20,root
From: https://www.cnblogs.com/cheyunhua/p/17971128

相关文章

  • vulnhub-devguru(sudo提权)
    环境准备:靶机192.168.0.100攻击机kali192.168.0.128演示使用nmap扫描全端口首先访问80端口 信息收集发现访问/.git/config存在,使用githack获取源码  访问adminer.php,为一个mysql的登录界面。 查找配置文件,找到mysql登录密码。/config/database.php 登录数......
  • 现代 IT 人一定要知道的 Ansible系列教程:Roles详解
    现代IT人一定要知道的Ansible系列教程:Roles详解AnsiblePlaybook提供了一个可重复、可重用、简单的配置管理和多机部署系统,非常适合部署复杂的应用程序。如果您需要多次使用Ansible执行任务,请编写一个playbook并将其置于源代码控制之下。然后,您可以使用playbook推出新配......
  • 自动化运维工具ansible 学习教程
    什么是ansibleAnsible是一个自动化的IT应用工具,用于自动化配置管理、部署、编排和协调系统和应用程序。它采用基于任务的语法,可以通过SSH或托管到远程节点的代理控制台自动执行各种操作。Ansible基于Python编写,并且易于学习和使用,可以实现基础设施即代码(Infrastructurea......
  • vulnhub-toppo(suid提权sudo提权)
    环境准备靶机192.168.116.138攻击机kali192.168.116.130演示直接访问webadmin目录下存在密码本使用ssh连接,账号ted,密码12345ted123使用项目进行探测LinEnumhttps://github.com/rebootuser/LinEnum 存在python可以使用suid提权使用python反弹shell /usr/b......
  • [FreeBSD]如何在FreeBSD 14.0上使用sudo命令
    Itispossibletousesutoexecutecommandsasroot,forexample%suroot-c'pkginspackage'thenenterrootpassword,oreditsudoersfileandaddyouruser,orgiveaccesstothewheelgroup:execute%suroot-cvisudo,thenuncommentCode:%w......
  • Ansible - Vault
     加密文件Ansible 有时需要访问一些敏感数据,如密码、Key等使用ansible-vault可以加密和解密数据#创建测试文件[root@controlansible]#echo123456>data.txt#加密文件[root@controlansible]#ansible-vaultencryptdata.txt#查看文件内容[root@controlansible......
  • Ansible - 高级语法
     error 处理机制默认ansible在遇到error会立刻停止playbook[root@controlansible]#cat~/ansible/error.yml----hosts:testtasks:-name:startaservicethatdoesnotexist.service:name:hehestate:started-name:t......
  • Ansible - 模块应用
     firewalld 模块使用firewalld模块可以配置防火墙策略[root@control~]#cat~/ansible/firewall.yml----hosts:agenttasks:-name:installfirewalld.yum:name:firewalldstate:present-name:runfirewalld.service:......
  • GDB调试之为断点执行命令(十一)
    调试代码下载地址断点执行命令commands的使用:为指定断点设置断点执行命令:保存和导入断点的设置信息: ......
  • 现代 IT 人一定要知道的 Ansible系列教程:playbook
    title='现代IT人一定要知道的Ansible系列教程:playbook'date=2023-12-23draft=falsesummary='AnsiblePlaybook提供了一个可重复、可重用、简单的配置管理和多机部署系统,非常适合部署复杂的应用程序。如果您需要多次使用Ansible执行任务,请编写一个playbook并将其......