【问题标题】:Ansible set password for complete playAnsible设置密码以完成游戏
【发布时间】:2016-03-11 15:02:25
【问题描述】:

我正在使用 Ansible 定义很多需要 sudo 权限的任务(运行任务的用户是非 root 用户,他是 sudo 组的成员)。为此,我每次定义 becomebecome_methodbecome_pass 时都使用以下代码。

# This is a sample task which needs sudo privileges
- name: copy the dnsmasq file
  template: src="templates/dnsmasq.conf" dest="/etc/dnsmasq.conf" owner="{{ROOT_USER}}" mode="0644" group="{{ROOT_USER}}"
  become: yes
  become_method: sudo
  become_pass: "{{ remote_user_password }}"
  notify: Restart dnsmasq 

我想在游戏级别 becomebecome_methodbecome_pass 设置以下属性。我可以设置 become, become_method 但我得到 ERROR: become_pass is not a legal parameter of an Ansible Play 这当然是有道理的,但是在播放级别定义密码的属性是什么?

我还尝试在 ansible_hosts 文件(我们在其中定义主机)中使用ansible_become=yes ansible_become_method=sudo ansible_become_user=MY_NON_ROOT_USER ansible_become_pass=My_PASSWD 进行权限提升,但它仍然不允许任务在没有 sudo 的情况下运行,并且权限被拒绝。

有没有一种方法可以为剧本定义一次密码以非交互式方式运行,这样我就不必为每个任务定义成为属性。

【问题讨论】:

    标签: passwords ansible ansible-playbook privileges


    【解决方案1】:

    我用:

    deploy.yml

    - name: Todo something
      hosts: all
      become: yes
      become_user: root
      become_method: su
    

    当你执行剧本时,像一个额外的变量一样传递密码。

     --extra-vars='ansible_become_pass=password'
    

    【讨论】:

    • 只有成为root的方式吗?我不想使用 root 用户执行任务。我将尝试通过普通用户使用它,看看它是否有效
    • 没有root不是唯一的方法。它也适用于其他用户。
    • 而不是传递 ansible_become_pass 我只是在 hosts 文件中提到了属性 ansible_become_pass 。还有两个属性 become: yesbecome_method: sudo 在主机下方,因为我只有一个主机。非常感谢。
    猜你喜欢
    • 2012-10-30
    • 1970-01-01
    • 1970-01-01
    • 2016-01-14
    • 1970-01-01
    • 2011-11-03
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    相关资源
    最近更新 更多