I added these debugs:

- name: Debug when statement
debug: 
var: acme_challenge_mydomain is changed and inventory_hostname in 
acme_challenge_mydomain['challenge_data']

- name: Debug the debug
debug: 
var: acme_challenge_mydomain is changed and inventory_hostname in 
acme_challenge_mydomain['authorizations']

And these output false and true, as expected

But right after that, I have the exact same statement in when:

- name: "Implement http-01 challenge files"
copy:
content: "{{ 
acme_challenge_mydomain['challenge_data'][inventory_hostname]['http-01']['resource_value']
 
}}"
dest: "/opt/FileMaker/FileMaker Server/HTTPServer/htdocs/{{ 
acme_challenge_mydomain['challenge_data'][inventory_hostname]['http-01']['resource']
 
}}"
owner: root
group: root
mode: u=rw,g=r,o=r
when: *acme_challenge_mydomain is changed and inventory_hostname in 
acme_challenge_mydomain['challenge_data']*

...but this task is still returning this error:

fatal: [travelweek.ddb.space]: FAILED! => {"msg": "The task includes an 
option with an undefined variable. The error was: 'dict object' has no 
attribute 'travelweek.ddb.space'\n\nThe error appears to be in 
'/home/ubuntu/fms-ansible-master/letsencrypt-issue.yml': line 83, column 5, 
but may\nbe elsewhere in the file depending on the exact syntax 
problem.\n\nThe offending line appears to be:\n\n\n  - name: \"Implement 
http-01 challenge files\"\n    ^ here\n"}

Note: I have upgraded ansible and ansible --version now returns ansible 
[core 2.12.1]


> How inventory_hostname would contain domain ? 
> Its just a special variable pre defined in ansible which contains name of 
the host for which task or play runs

That is exactly what I want and it seems to be working as I expect. Notice 
the true result from my second debug task above. I also know through debug 
that inventory_hostname contains the domain I want the certificate issued 
for. I also debug the acme_challenge_mydomain object and I see the domain 
there in authorizations, which is why the statement returns true.
On Tuesday, January 18, 2022 at 12:26:53 p.m. UTC-5 Jason Wood wrote:

> inventory_hostname is not the domain, it is a variable which contains the 
> domain. That's the part where I'm not sure how to reference it.
>
> I will try upgrading to see if that changes anything. Thanks!
>
> On Tuesday, January 18, 2022 at 12:03:31 p.m. UTC-5 Felix Fontein wrote:
>
>> Hi, 
>>
>> > I'm fairly new to this. I'm using ansible 2.9.6 on Ubuntu 20.04. 
>>
>> that version is really old and outdated. You should upgrade at least to 
>> the latest 2.9.x release (2.9.27), or even to the latest Ansible 
>> release (5.2.0). 
>>
>> This is the correct syntax (assuming your domain name is 
>> inventory_hostname): 
>>
>> > when: acme_challenge_mydomain is changed and inventory_hostname in 
>> > acme_challenge_mydomain['challenge_data'] 
>>
>> Without knowing your playbook... 
>>
>> > but in both cases the task executes even though I can see with a 
>> > debug task that challenge_data is empty: 
>> > ..."challenge_data": {},... 
>>
>> ...it's hard to say why this happens. 
>>
>> Same for this: 
>>
>> > My second question is... I have remaining_days set to 91, and there 
>> > are 89 days left, so shouldn't I have data in challenge_data? 
>>
>> There should be. (You can also set `force: true` to force regeneration.) 
>>
>> Are you sure that you are really running the playbook that you 
>> modified, and not something else? 
>>
>> Cheers, 
>> Felix 
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/19efc338-bddd-42f4-80fc-c9b6bb31864fn%40googlegroups.com.

Reply via email to