• ansible 执行sudo切换


    应用场景:当被控端的root被禁止远程登录,需要通过普通用户先连接上,然后进行提前

    一、基于命令做操作

    ###############
    ansible all -u wang -b -m script -a '/root/script/touch.sh' --ask-become-pass

     ansible tomcat_first -m script -a 'tomcat_reinforce.sh' -u sysadmin -b -K

    -u  指定普通用户
    -b  指定提权的用户,-b 代表root
    -m  指定要使用哪个模块
    -a  指定要执行的命令参数
    -K 指定提权是使用的口令
    --ask-become-pass: 输入密码进行提权

    二、ploybook实现sudo提前并执行脚本

    ##############

    ---
    - hosts: all
    remote_user: wang
    gather_facts: No
    become: yes
    become_method: sudo
    become_user: root
    tasks:
    - name: "create a new file"
    script: '/root/script/touch.sh'

    执行时加-K

    ansible-playbook touch.yml -K

    转载需注明出处,否则追究法律责任

  • 相关阅读:
    18周个人总结
    十六周个人总结
    排球积分规则程序
    十四周软件工程总结
    本周总结
    排球积分规则
    我的计算机生涯
    排球比赛记分员
    《怎样成为一个高手》观后感
    冲刺作业
  • 原文地址:https://www.cnblogs.com/guniang/p/13373388.html
Copyright © 2020-2023  润新知