lxd_container module for Ansible 2.5 contains this example:
# An example for creating a Ubuntu container and install python - hosts: localhost connection: local tasks: - name: Create a started container lxd_container: name: mycontainer state: started source: type: image mode: pull server: https://images.linuxcontainers.org protocol: lxd alias: ubuntu/xenial/amd64 profiles: ["default"] wait_for_ipv4_addresses: true timeout: 600 - name: check python is installed in container delegate_to: mycontainer raw: dpkg -s python register: python_install_check failed_when: python_install_check.rc not in [0, 1] changed_when: false - name: install python in container delegate_to: mycontainer raw: apt-get install -y python when: python_install_check.rc == 1
Is this some kind of insider knowledge that was used here and (prematurely?) optimizes how Ansible performs, based on the
mycontainer or something?
After all it's be much simpler to dispose of these last two tasks in favor of:
- name: install python in container delegate_to: mycontainer apt: pkg=python state=latest
... of course with the option to update the apt cache and all that.
So why resort to the
raw module here?
NB: I am asking this mainly because usually the documentation shows the canonical way of doing things. But from what I understand, canonically I am supposed to use the specific modules such as
apt rather than invoking