Score:0

Assert working in Ansible but not in AWX

hu flag

I've switched to AWX for my playbooks management and I can't seem to figure out this issue with assert. Here is a role that I've prepared:

- name: Run testing environment
  docker_compose:
    project_name: "testing"
    definition:
      version: '3.7'
      services:
        nginx:
          image: nginx:alpine
  register: output

- name: save output
  debug:
    var: output

- name: assert that container is running
  assert:
    that:
      - "nginx.testing_nginx_1.state.running"

When I run it with the ansible-playbook command, everything works well and the assert tasks returns the following:

TASK [test_role : assert that container is running] ************************************************************************************
ok: [testhost] => {
    "changed": false,
    "msg": "All assertions passed"
}

But when I run the same exact playbook using AWX, I get:

TASK [test_role : assert that container is running] ****************************
fatal: [testhost]: FAILED! => {"msg": "The conditional check 'nginx.testing_nginx_1.state.running' failed. The error was: error while evaluating conditional (nginx.testing_nginx_1.state.running): 'nginx' is undefined"}

Does anyone have an idea why this is happening?

Michael Hampton avatar
cz flag
There is something missing. You have not shown a playbook or a task or anything else that defines `nginx`.
dywan666 avatar
hu flag
I’ve shown everything. I took this from the module documentation: https://docs.ansible.com/ansible/latest/collections/community/docker/docker_compose_module.html#ansible-collections-community-docker-docker-compose-module - please take a loot at the last example.
Michael Hampton avatar
cz flag
Wow, this is not very well documented. It seems like those facts get populated for all the containers you've declared in docker-compose.yml whenever you call that module. Or at least that is what they are implying. I suspect you should look at the `output` from the previous task..
dywan666 avatar
hu flag
You are right. I can see that ansible_facts get populated with the `nginx` variable in my case. So why is this not working in AWX?
Zeitounator avatar
fr flag
Which version of ansible is your awx installation running ? I'd bet it is different and older than the one you are running manually. Try to install the same version in a virtualenv locally and run the playbook with it. Do you get the same error ?
dywan666 avatar
hu flag
I've decided to just use the info from the output, modified my playbooks slightly and everything is working correctly from both AWX and ansible running locally.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.