Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_fact not valid during rebuild #253

Open
Trashmee opened this issue May 22, 2021 · 5 comments
Open

set_fact not valid during rebuild #253

Trashmee opened this issue May 22, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@Trashmee
Copy link

Trashmee commented May 22, 2021

Hi,

I'm using set_fact in a couple of places, e.g. below to get the 'real' hostname to send collectd data to grafana for the host with its real name.

That works pretty well - until I rerun ansible-bender in which case he ignores the sets and uses a cached image, I assume.
I can rerun ansible-bender with --no-cache and it starts working again, however I'm feeling that I do something wrong, maybe?

Playbook extract

  - name: Get real hostname for conf file
    local_action: ansible.builtin.command cat /etc/hostname
    register: tmp
  - name: Store hostname as "desiredhostname"
    set_fact:
      desiredhostname: "{{ tmp.stdout }}"
  - name: debug
    debug:
      var: desiredhostname

Initial run - works fine

 #  ansible-bender build playbook.yml

PLAY [collectd - host overview to influxdb] ****************************************************************************************************************************************************************************************************************

TASK [Get real hostname for conf file] *********************************************************************************************************************************************************************************************************************
changed: [collectd-host-overview-influxdb-20210522-180419306640-cont]

TASK [Store hostname as "desiredhostname"] *****************************************************************************************************************************************************************************************************************
ok: [collectd-host-overview-influxdb-20210522-180419306640-cont]

TASK [debug] ***********************************************************************************************************************************************************************************************************************************************
ok: [collectd-host-overview-influxdb-20210522-180419306640-cont] => {
    "desiredhostname": "my-podman-host-01"
}
[..]

next run - fails

#  ansible-bender build playbook.yml

PLAY [collectd - host overview to influxdb] ****************************************************************************************************************************************************************************************************************

TASK [Get real hostname for conf file] *********************************************************************************************************************************************************************************************************************
loaded from cache: 'sha256:5dfbb8d9d4a86479e37e409111d3e99be218feafa2bdcfb903157b1acbb57e65'
skipping: [collectd-host-overview-influxdb-20210522-180746949622-cont]

TASK [Store hostname as "desiredhostname"] *****************************************************************************************************************************************************************************************************************
loaded from cache: 'sha256:c8f0e9152dc4200925eb700d770bd251cc622f36c0f88d0d79671f794cd6b894'
skipping: [collectd-host-overview-influxdb-20210522-180746949622-cont]

TASK [debug] ***********************************************************************************************************************************************************************************************************************************************
loaded from cache: 'sha256:3a6d887b77ce25ccce2da80d6664abd9b7d7614cfc229c95538f81f26b69f66b'
skipping: [collectd-host-overview-influxdb-20210522-180746949622-cont]

[..]

TASK [Copy & adept collectd.conf] **************************************************************************************************************************************************************************************************************************
fatal: [collectd-host-overview-influxdb-20210522-180746949622-cont]: FAILED! => {"changed": false, "msg": "AnsibleUndefinedVariable: 'desiredhostname' is undefined"}

PS: I really like ansible-bender - and I understand its a tough job to run a 1-man project like this. Please consider this as a request for input - not a complaint :-)

Is there a good way around this issue - besides building from scratch every time?

Itsmee

@Trashmee
Copy link
Author

Documentation contains some information (tags that influence the behavior) that I'll test.
https://ansible-community.github.io/ansible-bender/build/html/index.html

@TomasTomecek
Copy link
Collaborator

That works pretty well - until I rerun ansible-bender in which case he ignores the sets and uses a cached image, I assume.
I can rerun ansible-bender with --no-cache and it starts working again, however I'm feeling that I do something wrong, maybe?

This is correct, you should run with --no-cache to get consistent results. I feel like this recent suggestion would also help you #256

PS: I really like ansible-bender - and I understand its a tough job to run a 1-man project like this. Please consider this as a request for input - not a complaint :-)

No worries, thank you for your time opening this!

Is there a good way around this issue - besides building from scratch every time?

Hmm, this actually sounds like a bug as bender should not cache set_fact tasks since, as you state, variables are no longer defined.

@TomasTomecek TomasTomecek added the bug Something isn't working label Jun 25, 2021
@grzegorznowak
Copy link

Hey,
I'm getting hit by some form of set_fact skipping as well. ie.

https://github.com/grzegorznowak/cardano-node-role/blob/5ae3a125e375a5f9f0095b87177bcd2c6674d506/tasks/infrastructure/dependencies.yml#L54

when ran on a pristine system it should always hit the rescue: part of the block, and so it generally does, confirmed by CI jobs as well as places we're using this role in, other than trying to containerize it with Bender.

when built via ansible-bender the output from Ansible goes like this:
(with or without the --no-cache flag)

TASK [grzegorznowak.cardano_node : Dependencies | Get the current ghc version] ***
fatal: [pab-20220207-074452474105-cont]: FAILED! => {"changed": false, "cmd": ["./ghc", "--numeric-version"], "delta": null, "end": null, "msg": "Unable to change directory before execution: [Errno 2] No such file or directory: b'/root/.ghcup/bin'", "rc": null, "start": null, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}
07:45:46.005 snapshoter.py     ERROR  error while running the build: '>' not supported between instances of 'NoneType' and 'int'

TASK [grzegorznowak.cardano_node : Dependencies | set empty cabal versions] ****
skipping: [pab-20220207-074452474105-cont]

I've tried some combinations of ansible versions, and caching flags but none seem to made any effect on skipping: of this task.
Do you maybe have some thoughts on that @TomasTomecek 🤔 ?

@grzegorznowak
Copy link

ah ok I see it fails on this statement:

if task_result.is_failed() or task_result._result.get("rc", 0) > 0:

task_result._result.get("rc", 0) >0 trying to compare NoneType with int

get() probably doesn't default to 0 in this case.

@TomasTomecek
Copy link
Collaborator

@grzegorznowak thanks for digging into it! I will gladly accept a pull request :)

(I am fairly busy this week so it may take me a few days to respond but things should be getting better in the coming weeks)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants