Thanks, Walter.
We're not using static addresses but dynamic. If we were, it would be
easier. I figured out the Ansible fact to grab the IP but this only grabs
it for a single host.
ansible_facts["azure_vm"]["network_profile"]["network_interfaces"][0]["properties"]["ip_configurations"][0]["private_ip_address"]
I wrote a simple task to loop through the host list provided in the Ansible
survey to dump the ips to stdout.
- name: Gather specific Ansible facts
debug:
msg: "{{ hostvars[item]['ansible_default_ipv4']['address'] }}"
loop: "{{ linux_hosts }}"
but it looks like it can't find the host(s).
"msg": "The task includes an option with an undefined variable. The error
was: \"hostvars['rheltest0709a']\" is undefined.
Thanks!
On Tuesday, July 9, 2024 at 10:00:09 AM UTC-6 Rowe, Walter P. (Fed) wrote:
> You need names and corresponding IP addresses for an inventory.
>
> Walter
> --
> Walter Rowe, Division Chief
> Infrastructure Services Division
> Mobile: 202.355.4123 <(202)%20355-4123>
>
> On Jul 9, 2024, at 11:52 AM, HBach <[email protected]> wrote:
>
> Hi, community,
>
> I am creating a deployment workflow using the Ansible Automation Platform
> (AAP) and, right now, the workflow is composed of two job templates. The
> first job template creates the actual vms and the the second job template
> is used for some post-build configuration tasks. I want to use the
> inventory generated in the first job template for the second job template.
>
> Right now, I am having AAP reach back to itself via the AAP API and create
> an inventory. I have also used the set_stats module to create an artifact
> that the second job template can see.
>
> - name: Set stats to pass inventory
> ansible.builtin.set_stats:
> data:
> target_hosts: "{{ linux_hosts }}"
>
> - name: Get an AAP API Token and store it as new_token
> register: new_token
> ansible.builtin.uri:
> url: "https://<redacted>/api/v2/tokens/"
> method: POST
> user: admin
> password: "{{ survey_controller_passwd }}"
> validate_certs: false
> force_basic_auth: true
> status_code: 201
> return_content: true
>
> - name: Azure inventory update
> ansible.controller.host:
> controller_host: "https://<redacted>/"
> controller_password: "{{ survey_controller_passwd }}"
> controller_username: 'admin'
> controller_oauthtoken: "{{ new_token.json.token }}"
> name: "{{ linux_hosts }}"
> inventory: "Azure-test"
> state: present
> enabled: true
>
> The artifact is created and the new inventory on AAP is updated when job
> template 1 completes.
>
> {
> "target_hosts": [
> "rheltest0701c"
> ]
> }
>
> But, the second job template fails as it cannot find the host(s).
> *[WARNING]: Could not match supplied host pattern, ignoring: target_hosts*
>
> Any idea, folks?
>
>
> --
> 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/aa0fcd58-3f55-4c9a-8ea6-2d0e28fa3495n%40googlegroups.com
>
> <https://groups.google.com/d/msgid/ansible-project/aa0fcd58-3f55-4c9a-8ea6-2d0e28fa3495n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
>
>
--
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/fd7b18b7-e4f0-43af-9d79-e3f02ca3b089n%40googlegroups.com.