Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set env. variable in ansible apt module

Tags:

ubuntu

ansible

I'm using the ansible apt module to install packages on Ubuntu hosts:

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

I now want to install sudo-ldap, but following what I did above doesn't work:

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

To install sudo-ldap require that export SUDO_FORCE_REMOVE=yes be set beforehand. If I were to do this on the commandline I'd do the following:

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

In fact, I've used this in my ansible task:

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

But there must be a better way to set this environmental variable so that I can use the apt module directly, rather than going to the shell?

like image 427
Nathan S. Watson-Haigh Avatar asked Dec 24 '22 15:12

Nathan S. Watson-Haigh


1 Answers

You can set env vars on every task like this:

---
- name: Install sudo-ldap
  apt: name=sudo-ldap state=present
  environment:
    SUDO_FORCE_REMOVE: yes
like image 147
Emilio Garçia Avatar answered Dec 27 '22 05:12

Emilio Garçia