geerlingguy / docker-ubuntu2004-ansible

Ubuntu 20.04 LTS (Focal Fossa) Docker container for Ansible playbook and role testing.
https://hub.docker.com/r/geerlingguy/docker-ubuntu2004-ansible
MIT License
83 stars 49 forks source link

apt install package (molecule testing) #23

Closed DarksideVT closed 2 years ago

DarksideVT commented 2 years ago

New to molecule here. So guide me with anything I'm missing, please.

converge.yml

- name: Converge
  hosts: all
  tasks:
    - name: Update apt cache
      apt:
        update_cache: true
        cache_valid_time: 3600
    - name: "Include base_install"
      include_role:
        name: "base_install"

molecule.yml

---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: molecule-base_install
    image: geerlingguy/docker-ubuntu2004-ansible
    # command: ''
    # volumes:
    #   - /sys/fs/cgroup:/sys/fs/cgroup:ro
    # privilaged: true
    # pre_build_image: true
provisioner:
  name: ansible
  lint: |
    yamllint .
    ansible-lint
verifier:
  name: ansible

main.yml

---
- name: Install nano,htop,snapd
  package:
    name: 
    - nano
    - htop
    - snapd
    state: present

error

fatal: [molecule-base_install]: FAILED! => {"changed": false, "msg": "No package matching 'nano' is available"}

Expected behavior

APT installs nano, htop, and snapd

geerlingguy commented 2 years ago

You probably need to add a task to update_cache for apt, otherwise the cache will be outdated and won't know where to find packages to install.

DarksideVT commented 2 years ago

@geerlingguy is that the case even though I've done it in the converge.yml?

geerlingguy commented 2 years ago

When you run the playbook, does it show changed for that apt cache update task?

DarksideVT commented 2 years ago

Looks like I've fallen victim to not taking my own advice. I rebooted and now it seems to work. Thanks for the help!