ubuntu - 设置环境。 ansible apt模块中的变量

标签 ubuntu ansible

我正在使用 ansible apt 模块在 Ubuntu 主机上安装软件包:

---
-name: Install htop
  apt: name=htop state=present

我现在想安装 sudo-ldap,但按照我上面所做的操作不起作用:

---
-name: Install sudo-ldap
  apt: name=sudo-ldap state=present

要安装 sudo-ldap,需要预先设置 export SUDO_FORCE_REMOVE=yes。如果我要在命令行上执行此操作,我会执行以下操作:

SUDO_FORCE_REMOVE=yes apt-get install -y sudo-ldap

事实上,我已经在我的 ansible 任务中使用了它:

---
- name: Install sudo-ldap
  shell: SUDO_FORCE_REMOVE=yes apt-get install -y sudo-ldap
  args:
    creates: "/etc/sudo-ldap.conf"

但必须有更好的方法来设置这个环境变量,以便我可以直接使用 apt 模块,而不是去 shell 吗?

最佳答案

我知道它很旧,但是 SUDO_FORCE_REMOVE: yes 将不起作用。我们可以在这里看到 yes 变成了 True:

<192.168.33.11> SSH: EXEC ssh -o ControlMaster=auto -o ControlPersist=60s -o     StrictHostKeyChecking=no -o     'IdentityFile=".vagrant/machines/anyserver/virtualbox/private_key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=vagrant -o ConnectTimeout=10 -o ControlPath=/home/mrbits/.ansible/cp/ansible-ssh-%h-%p-%r -tt 192.168.33.11 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-vmofyrkeoiwkculfgovhifhhoylkbfrj; **SUDO_FORCE_REMOVE=True** /usr/bin/python /home/vagrant/.ansible/tmp/ansible-tmp-1487325724.54-173290784938544/apt.py; rm -rf "/home/vagrant/.ansible/tmp/ansible-tmp-1487325724.54-173290784938544/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && sleep 0'"'"''

apt 在 SUDO_FORCE_REMOVE 上期望值 "yes",因此正确的方法是:

---
- name: Install sudo-ldap
  apt: name=sudo-ldap state=present
  environment:
    SUDO_FORCE_REMOVE: "yes"

只是我的 2 美分。

干杯

关于ubuntu - 设置环境。 ansible apt模块中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31956900/

相关文章:

ubuntu - Docker 错误绑定(bind) : address already in use

ansible - Ansible 手册中的 Jinja2

Ansible playbook 使用集合中定义的角色

ssh - 破坏 Vagrant 上 Ansible 中的代理转发

dependencies - 如何为角色指定 ansible 前置任务?

linux - 在Linux(Xubuntu 18.04)上无法使用pyserial进行读取/写入

ubuntu - Netbeans 无法在 ubuntu 中打开

ubuntu - arm交叉编译时如何处理Boost之类的库?

python - 第一次安装virtualenvwrapper,无法运行初始化钩子(Hook)

ssh - Ansible:权限被拒绝(公钥、密码)