Skip to content

Ansible

Rob Nagler edited this page Jun 19, 2018 · 6 revisions

Ansible

I'm finding Ansible to be a pain. for the some of the same reasons as Salt.

shell command parsing:

This issue explains the problem, but here's the code:

- name: add container-storage-setup
  args:
    creates: "{{ docker.dm.thinpooldev }}"
    executable: /bin/bash
  shell: |
    set -e
    cd /tmp
    rm -rf container-storage-setup
    git clone https://github.com/projectatomic/container-storage-setup
    cd container-storage-setup
    rm -rf container-storage-setup
    cat > rs-conf <<'EOF'
    CONTAINER_THINPOOL='{{ docker.dm.thinpool }}'
    VG='{{ docker.dm.volume_group }}'
    DEVS='{{ docker.dm.block_device }}'
    EOF
    bash container-storage-setup.sh rs-conf ignore-output
    cd ..
    rm -rf container-storage-setup

This correct YAML ends up failing, because shell puts a leading space on all lines so that the script looks like:

 set -e
 cd /tmp
 rm -rf container-storage-setup
 git clone https://github.com/projectatomic/container-storage-setup
 cd container-storage-setup
 rm -rf container-storage-setup
 cat > rs-conf <<'EOF'
 CONTAINER_THINPOOL='{{ docker.dm.thinpool }}'
 VG='{{ docker.dm.volume_group }}'
 DEVS='{{ docker.dm.block_device }}'
 EOF
 bash container-storage-setup.sh rs-conf ignore-output
 cd ..
 rm -rf container-storage-setup

Which unfortunately creates a file rs-conf, but doesn't run container-storage-setup.sh. Now even though shell knows {{ docker.dm.thinpooldev }} should be created, it isn't, but the task completes, docker then fails to start.

It would be better to have a single script that creates the storage and enables Docker.

firewalld doesn't restart

Does not restart:

- name: restart firewalld
  service: name=firewalld state=restarted

nfs doesn't restart

If you get a failure, then it doesn't restart. exportfs is idempotent, just run it.

Include backup files as vars

Includes ~ backup files from emacs as variables.

jinja not consistent

meta/main.yml and defaults/main.yml do not accept Jinja:

ERROR! Syntax Error while loading YAML.

The error appears to have been in '/var/lib/ansible/ansible-conf/roles/mpi_cluster/defaults/main.yml': line 37, column 8, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

       mpi_bin_d: /var/lib/jupyter/mpi_bin
       {% if rs_role == "mpi_cluster_coordinator" %}
       ^ here

In general, too many syntaxes: ansible.cfg, inventory, variables, tasks, files/directories, etc.

Clone this wiki locally