如何使用——使用ansible 1.9.4要求成为通行证

如何使用——使用ansible 1.9.4要求成为通行证,ansible,ansible-playbook,Ansible,Ansible Playbook,我是ansible的新用户。我正试图使用权限提升功能将一行附加到root拥有的文件中 下面的文档告诉我可以使用--ask been pass with been_user提示输入been_user密码,但我不知道如何使用它 我目前使用的代码如下: - name: Add deploy to sudoers remote_user: me become: yes become_method: su ask_become_pass:

我是ansible的新用户。我正试图使用权限提升功能将一行附加到root拥有的文件中

下面的文档告诉我可以使用--ask been pass with been_user提示输入been_user密码,但我不知道如何使用它

我目前使用的代码如下:

- name: Add deploy to sudoers
        remote_user: me
        become: yes
        become_method: su
        ask_become_pass: true
        lineinfile:
          dest=/etc/somefile
          line=sometext
          regexp="^sometext"
          owner=root
          state=present
          insertafter=EOF
          create=True
这给了我一个错误: 错误:ask_BE_pass不是Ansible任务或处理程序中的合法参数

有人能告诉我我在这里可能做错了什么吗


提前感谢。

文档中说,
ask\u been\u pass
是一个命令行参数。这意味着您必须在执行剧本时使用它:

ansible playbook*playbook name*--询问成为通行证

在这种情况下,ansible将要求输入密码


另一个选项
ansible\u been\u pass
可以在库存中使用,也可以作为额外变量。在那里,您可以在执行剧本时设置密码。

@Capri90演示了如何使用

但是

当使用
--ask been pass
时,用户每次都需要手动输入密码,因此要避免输入密码,请遵循以下步骤

而是使用下面的配置

playbook.yml

ansible.cfg

yo\u ansible\u inventory.txt

注意
ansible\u been\u pass
命令
sudo-apt-get-install-npm
启动时将使用

[all:vars]
ansible_connection=ssh
ansible_user=tom    
ansible_become_pass=jerrypassword

[yo_my_ips]
192.168.1.105 

谢谢@Capri90的回答。你的例子和你解释的一模一样。不幸的是,我仍然收到一个权限被拒绝的错误。看起来Been_用户重新建立了一个ssh连接,成为了我想要成为的用户。因为我想在远程系统(Ubuntu)上使用su根目录,所以这是不可能的。我怎样才能在不重新建立ssh连接的情况下访问root?这可能吗?最终的结果是我想给一个没有密码提示的用户管理员权限。相当于username ALL=(ALL)NOPASSWD:ALL我一直无法找到成功的方法。不客气。Ubuntu允许通过ssh进行根访问。只需更改设置。另外,我不确定是否要创建用户(使用ansible模块)或更改现有用户。
[defaults]
inventory = yo_ansible_inventory.txt
[all:vars]
ansible_connection=ssh
ansible_user=tom    
ansible_become_pass=jerrypassword

[yo_my_ips]
192.168.1.105