semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform, OpenTofu, PowerShell and other DevOps tools.
https://semaphoreui.com
MIT License
10.6k stars 1.07k forks source link

The job runs and completes successfully, but not applied #1374

Closed S0b1t closed 1 year ago

S0b1t commented 1 year ago

What I did ?

I installed semaphore from docs and created a job to install the Portainer agent in a Docker container on my servers.

What did I expect to see?

I was expecting to see Portainer Agent running on Docker Container

What did I see instead?

Container does not run even if the job was completed successfully

This is my job: image image

Playbook:

---
# tasks file for portainer_agent_ansible_playbook
- name: Check if portainer agent network exists
  shell: docker network ls -q -f name="{{ network }}"
  register: portainer_agent_network
  ignore_errors: true

- name: Create "{{ network }}" docker network, if doesn't exist
  docker_network:
    name: "{{ network }}"
  when: portainer_agent_network.stdout_lines | length == 0

- name: Check if portainer_agent container exists
  shell: docker ps -q -f name="{{ name }}"
  register: portainer_agent_container
  ignore_errors: true

- name: Running Portainer Agent in Docker Container
  docker_container:
    name: "{{ name }}"
    image: "{{ image }}:{{ tag }}"
    volumes:
      - "{{ bind_volume }}:{{ container_volume }}"
      - "{{docker_sock_path}}:{{ docker_sock_path }}"
    ports:
      - "{{ default_external_port }}:{{ default_internal_port }}"
    restart_policy: "{{ restart }}"
    networks:
      - name: "{{ network }}"
  when: portainer_agent_container.stdout_lines | length == 0

portainer_agent_ansible_playbook/vars/main.yml

---
# vars file for portainer_agent_ansible_playbook
network: "my-network"
name: "portainer_agent"
image: "portainer/agent"
tag: 2.18.3
bind_volume: "/data/docker/volumes"
container_volume: "/var/lib/docker/volumes"
docker_sock_path: "/var/run/docker.sock"
default_external_port: 9001
default_internal_port: 9001
restart: "always"
hosts: TK-MVNO-001

run_playbook.yml

---
- hosts: "{{ hosts }}"
  become: yes

  roles:
    - portainer_agent_ansible_playbook

If I run my playbook with ansible-playbook run_playbook.yml -K it works fine

image

Guess

As you can see in the screenshot, the semaphore skips some steps and the sequence is sometimes displayed incorrectly. I changed my playbook many times but the semaphore didn't change the playbook, I mean are there any caches?! I think they are the problem.

ansibleguy commented 1 year ago

Greetings.

Semaphore is also just executing 'ansible-playbook' in the background. So 'Semaphore' can't skip Ansible-tasks. That's not possible.

You mentioned you have modified your playbook. Semaphore will always use the Playbook stored in the configured 'Repository'. ('pandora' in your case) Have you modified the playbook inside this repository? Else Semaphore will not pick-up on the changes. As far as I can tell there is no 'Playbook cache' in use. It will always be executed from the filesystem (as configured).

If you are unsure - the repository configuration would be nice to have.

- AnsibleGuy

S0b1t commented 1 year ago

Please look at the screenshot again. As you can see in the last picture, the jobs named "check if portainer agent network exists" and "check if portainer_agent container exists" are running (state changed). But on semaphore it skips, whether that causes a problem or not, I don't know. But the task called "Running Portainer agent in Docker container" was completed successfully (status changed) which means the Docker container should be running (but there is no container), correct me if I'm wrong.

This is my repo: image image

updated: tagging @ansibleguy

ansibleguy commented 1 year ago

Thank you. Can it be that you have 'check_mode' enabled? Because the two tasks 'skipped' are 'ansible.builtin.shell' module-tasks that will be skipped in that mode!

Also just to mention it: Best-practice is that calls to docker should use the 'community.docker' modules instead of shell-commands. (those might support check-mode)

S0b1t commented 1 year ago

Can it be that you have 'check_mode' enabled? Because the two tasks 'skipped' are 'ansible.builtin.shell' module-tasks that will be skipped in that mode!

You were right, thanks @ansibleguy