ansible-bender
ansible-bender copied to clipboard
set_fact not valid during rebuild
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
Documentation contains some information (tags that influence the behavior) that I'll test. https://ansible-community.github.io/ansible-bender/build/html/index.html
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 https://github.com/ansible-community/ansible-bender/issues/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.
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 🤔 ?
ah ok I see it fails on this statement: https://github.com/ansible-community/ansible-bender/blob/35c7b4c58a5345142f0034af426a4e232bfd6267/ansible_bender/callback_plugins/snapshoter.py#L43
task_result._result.get("rc", 0) >0
trying to compare NoneType
with int
get() probably doesn't default to 0
in this case.
@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)