Re: [ansible-project] Looping a task until it succeeds
Thanks for the explanation. The default piece was tripping me up but it all makes total sense now. On Friday, June 26, 2020 at 11:37:53 AM UTC-4, Vladimir Botka wrote: > > On Fri, 26 Jun 2020 06:46:04 -0700 (PDT) > Cade Lambert > wrote: > > > Can you explain what's happening in this statement: > > condition: "{{ (result|default({'rc': 1})).rc == 0 }}" > > Sure. Let's start with the fact that "result" is available at controller > after each iteration. It's necessary to keep in mind that the remote host > is > the origin of the "result". Hence, the data must be sent from the remote > host > to the controller after each iteration. > > If you want to see what data is available in the dictionary "result" after > each iteration run this task > > - shell: 'echo {{ condition }} && [ "{{ item }}" -gt "2" ]' > loop: "{{ range(1, 3 + 1)|list }}" > register: result > ignore_errors: true > vars: > condition: '{{ result|default({"rc": 1}) }}' > - debug: > var: result > > You'll see that "result" of each iteration will be concatenated into the > list "result.results". Knowing this, simply pickup an attribute to test > the > success of each iteration. You've already found out how. > > Now to the "condition". The "when" statement is evaluated at each > iteration > and before the first iteration as well. There is no variable "result" > available before the first iteration and the task would crash. Hence, > "default" value is needed. In this case > > result|default({"rc": 1}) > > The attribute "rc" is tested for success. Hence the default value {"rc": > 1} > because we always want to run the first iteration. Next iterations > evaluate > de facto the following expression because "result" was provided by the > previous iteration > > result.rc == 0 > > > HTH, > > -vlado > > -- > Vladimir Botka > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5c2f6757-b027-48de-9ddb-da4785aced68o%40googlegroups.com.
Re: [ansible-project] Looping a task until it succeeds
Awesome, I got it to work with my nios task as well, just had to change rc to failed since I had no rc in my output. I'm not totally sure I follow why it skips after the first success though. Can you explain what's happening in this statement: condition: "{{ (result|default({'rc': 1})).rc == 0 }}" On Thursday, June 25, 2020 at 5:13:16 PM UTC-4, Vladimir Botka wrote: > > On Thu, 25 Jun 2020 13:05:23 -0400 > Brian Coca > wrote: > > > something like (might need to tweak syntax to get right): > > when: not select(result[|deault({'results': []}, 'success' )|list > > will skip the rest of the iterations once one succeeds > > Thank you very much! I got it. For example > > - command: '[ "{{ item }}" -gt "3" ]' > loop: "{{ range(1, 5 + 1)|list }}" > register: result > ignore_errors: true > when: not condition > vars: > condition: "{{ (result|default({'rc': 1})).rc == 0 }}" > > gives > > changed: [localhost] => (item=4) > skipping: [localhost] => (item=5) > ...ignoring > > > -- > Vladimir Botka > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a5641bbb-5e7e-46e2-bb59-d78448cbdb63o%40googlegroups.com.
Re: [ansible-project] Looping a task until it succeeds
I might mess with trying to get it to search partial hostnames later. If I could use a wildcard, I could generate a list in a variable and then manipulate that list. On Thursday, June 25, 2020 at 2:42:27 PM UTC-4, Stefan Hornburg (Racke) wrote: > > On 6/25/20 8:13 PM, Cade Lambert wrote: > > So I tried using the nios module to query hostnames but I couldn't find > a way to query part of a hostname. It seemed > > that it only accepted exact names. Is this something you've done > before? > > No, but in general it scales better to see what's there and create the new > record based on that (2 API calls) instead > of blindly trying out (1 + n API calls). > > Regards > Racke > > > > > On Thursday, June 25, 2020 at 1:22:23 PM UTC-4, Stefan Hornburg (Racke) > wrote: > > > > On 6/25/20 3:51 PM, Cade Lambert wrote: > > > My use case: we use Infoblox for our DNS. What I'm trying to do > is automatically create a host record with the next > > > available hostname that isn't already in DNS. My plan was to loop > through a formatted hostname, incrementing a > > number > > > in that hostname until a hostname is found that isn't already in > Infoblox. Here's what I have so far: > > > > > > - name: Assign next available IP address in your choosen vlan > > > nios_host_record: > > > name: "{{ 'hostname%02d' | format(item) }}" > > > ipv4: > > > - address: {nios_next_ip: '1.1.1.0/24 <http://1.1.1.0/24>'} > > > > state: present > > > view: Internal > > > provider: "{{ provider }}" > > > loop: "{{ range(1, 5 + 1)|list }}" > > > register: loop_result > > > ignore_errors: true > > > > > > > Hello Cade, > > > > you could query first the existing DNS records in Infoblox and > determine the next hostname from these results. > > > > Regards > > Racke > > > > > So for this example, in the DNS, there's already a hostname01, > hostname02, hostname03. The output will be: > > > > > > TASK [Assign next available IP address in your choosen vlan] > > > > > > *** > > > > > > > failed: [localhost] (item=1) => {"ansible_loop_var": "item", > "attempts": 1, "changed": false, "code": > > > "Client.Ibap.Data.Conflict", "item": 1, "msg": "The record > 'hostname01' already exists.", "operation": > > "create_object", > > > "type": "AdmConDataError"} > > > failed: [localhost] (item=2) => {"ansible_loop_var": "item", > "attempts": 1, "changed": false, "code": > > > "Client.Ibap.Data.Conflict", "item": 2, "msg": "The record > 'hostname02' already exists.", "operation": > > "create_object", > > > "type": "AdmConDataError"} > > > failed: [localhost] (item=3) => {"ansible_loop_var": "item", > "attempts": 1, "changed": false, "code": > > > "Client.Ibap.Data.Conflict", "item": 3, "msg": "The record > 'hostname03' already exists.", "operation": > > "create_object", > > > "type": "AdmConDataError"} > > > changed: [localhost] => (item=4) > > > changed: [localhost] => (item=5) > > > > > > I'd like it to stop processing the loop at item=4, since that's > the first success. I've messed with a few different > > > until statements at the end but nothing seems to really work. > Thanks. > > > > > > -- > > > 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 > > > ansible...@googlegroups.com ansible-project+unsubscr...@googlegroups.com > >. > > > To view this discussion on the web visit > > > > https://groups.g
Re: [ansible-project] Looping a task until it succeeds
So I tried using the nios module to query hostnames but I couldn't find a way to query part of a hostname. It seemed that it only accepted exact names. Is this something you've done before? On Thursday, June 25, 2020 at 1:22:23 PM UTC-4, Stefan Hornburg (Racke) wrote: > > On 6/25/20 3:51 PM, Cade Lambert wrote: > > My use case: we use Infoblox for our DNS. What I'm trying to do is > automatically create a host record with the next > > available hostname that isn't already in DNS. My plan was to loop > through a formatted hostname, incrementing a number > > in that hostname until a hostname is found that isn't already in > Infoblox. Here's what I have so far: > > > > - name: Assign next available IP address in your choosen vlan > > nios_host_record: > > name: "{{ 'hostname%02d' | format(item) }}" > > ipv4: > > - address: {nios_next_ip: '1.1.1.0/24'} > > state: present > > view: Internal > > provider: "{{ provider }}" > > loop: "{{ range(1, 5 + 1)|list }}" > > register: loop_result > > ignore_errors: true > > > > Hello Cade, > > you could query first the existing DNS records in Infoblox and determine > the next hostname from these results. > > Regards > Racke > > > So for this example, in the DNS, there's already a hostname01, > hostname02, hostname03. The output will be: > > > > TASK [Assign next available IP address in your choosen vlan] > > > *** > > > > failed: [localhost] (item=1) => {"ansible_loop_var": "item", "attempts": > 1, "changed": false, "code": > > "Client.Ibap.Data.Conflict", "item": 1, "msg": "The record 'hostname01' > already exists.", "operation": "create_object", > > "type": "AdmConDataError"} > > failed: [localhost] (item=2) => {"ansible_loop_var": "item", "attempts": > 1, "changed": false, "code": > > "Client.Ibap.Data.Conflict", "item": 2, "msg": "The record 'hostname02' > already exists.", "operation": "create_object", > > "type": "AdmConDataError"} > > failed: [localhost] (item=3) => {"ansible_loop_var": "item", "attempts": > 1, "changed": false, "code": > > "Client.Ibap.Data.Conflict", "item": 3, "msg": "The record 'hostname03' > already exists.", "operation": "create_object", > > "type": "AdmConDataError"} > > changed: [localhost] => (item=4) > > changed: [localhost] => (item=5) > > > > I'd like it to stop processing the loop at item=4, since that's the > first success. I've messed with a few different > > until statements at the end but nothing seems to really work. Thanks. > > > > -- > > 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 > > ansible...@googlegroups.com ansible-project+unsubscr...@googlegroups.com >. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/ansible-project/3687c5df-e90d-4d50-af6c-38b467951ad3o%40googlegroups.com > > > < > https://groups.google.com/d/msgid/ansible-project/3687c5df-e90d-4d50-af6c-38b467951ad3o%40googlegroups.com?utm_medium=email_source=footer>. > > > > > -- > Ecommerce and Linux consulting + Perl and web application programming. > Debian and Sympa administration. Provisioning with Ansible. > > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5c53d589-f668-41ce-babe-6ff3576bdbd9o%40googlegroups.com.
Re: [ansible-project] Looping a task until it succeeds
I messed around with this a little bit. It gets a little complicated to parse the next available hostname from the output but I did get it to work. - set_fact: first: "{{ result.results| selectattr('rc', 'equalto', 1)| map(attribute='item')| first }}" - debug: msg: "{{ result.results[first|int-1].cmd | regex_search('(?<=\\s).*') }}" This will give me: ok: [localhost] => { "msg": "hostname04" } So yes, this is another way I could achieve finding the next available hostname. On Thursday, June 25, 2020 at 11:56:48 AM UTC-4, Vladimir Botka wrote: > > > > > On Thu, 25 Jun 2020 06:51:12 -0700 (PDT) > > > > Cade Lambert > wrote: > > > > I'd like it to stop processing the loop at item=4, since that's the > > > > > first success. > > > > This is not possible atm. All items in the loop will be processed. The > > > details have already been discussed here > > > https://groups.google.com/forum/#!topic/ansible-project/uJqSmkKTpZc > > > Ok, I tried the 'hack' ... Ugly but it works. > > There is no hack available to break a loop. All items of a loop will be > processed atm. Wouldn't be better to test the registered results? For > example > > - command: '[ "{{ item }}" -gt "3" ]' > loop: "{{ range(1, 5 + 1)|list }}" > register: result > ignore_errors: true > - set_fact: > first: "{{ result.results| >selectattr('rc', '==', 0)| >map(attribute='item')| >first }}" > - debug: > var: first > > gives > > first: '4' > > -- > Vladimir Botka > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3badff86-41c0-4ea3-99f7-a83740a9539co%40googlegroups.com.
Re: [ansible-project] Looping a task until it succeeds
Ok, I tried the 'hack' in that thread but it didn't work for me. I was hoping for a clean way to do what I need but l can't think of anything clean, so I went with functional. I got the result I was looking for by using the same loop against the host command on the shell, dumping that into a file, and then grepping the first hostname that isn't found. Ugly but it works. On Thursday, June 25, 2020 at 10:21:36 AM UTC-4, Vladimir Botka wrote: > > On Thu, 25 Jun 2020 06:51:12 -0700 (PDT) > Cade Lambert > wrote: > > > I'd like it to stop processing the loop at item=4, since that's the > first > > success. > > This is not possible atm. All items in the loop will be processed. The > details have already been discussed here > https://groups.google.com/forum/#!topic/ansible-project/uJqSmkKTpZc > > -- > Vladimir Botka > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/bb1f8b61-2032-4aa0-a12f-d684574505c9o%40googlegroups.com.
[ansible-project] Looping a task until it succeeds
My use case: we use Infoblox for our DNS. What I'm trying to do is automatically create a host record with the next available hostname that isn't already in DNS. My plan was to loop through a formatted hostname, incrementing a number in that hostname until a hostname is found that isn't already in Infoblox. Here's what I have so far: - name: Assign next available IP address in your choosen vlan nios_host_record: name: "{{ 'hostname%02d' | format(item) }}" ipv4: - address: {nios_next_ip: '1.1.1.0/24'} state: present view: Internal provider: "{{ provider }}" loop: "{{ range(1, 5 + 1)|list }}" register: loop_result ignore_errors: true So for this example, in the DNS, there's already a hostname01, hostname02, hostname03. The output will be: TASK [Assign next available IP address in your choosen vlan] *** failed: [localhost] (item=1) => {"ansible_loop_var": "item", "attempts": 1, "changed": false, "code": "Client.Ibap.Data.Conflict", "item": 1, "msg": "The record 'hostname01' already exists.", "operation": "create_object", "type": "AdmConDataError"} failed: [localhost] (item=2) => {"ansible_loop_var": "item", "attempts": 1, "changed": false, "code": "Client.Ibap.Data.Conflict", "item": 2, "msg": "The record 'hostname02' already exists.", "operation": "create_object", "type": "AdmConDataError"} failed: [localhost] (item=3) => {"ansible_loop_var": "item", "attempts": 1, "changed": false, "code": "Client.Ibap.Data.Conflict", "item": 3, "msg": "The record 'hostname03' already exists.", "operation": "create_object", "type": "AdmConDataError"} changed: [localhost] => (item=4) changed: [localhost] => (item=5) I'd like it to stop processing the loop at item=4, since that's the first success. I've messed with a few different until statements at the end but nothing seems to really work. Thanks. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3687c5df-e90d-4d50-af6c-38b467951ad3o%40googlegroups.com.
Re: [ansible-project] Re: Testing Authentication with Ansible
I've tried it with the URI module and I don't believe it's doing what I'd like. It will return a successful authentication even when I use incorrect credentials, so I'm not sure what it's really doing. On Tuesday, March 10, 2020 at 5:09:22 PM UTC-4, J Hawkesworth wrote: > > I think you should be able to do this with uri module, but you might need > to check the http response code as well. An unsuccessful http request with > basic authentication will return a response from the server, but it will > typically not have a 200 (OK) response code, but instead have something > like a 401 Unauthorised or 403 Forbidden response. > > Hope this helps, > > Jon > > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/106cd44b-215d-40fb-845d-c6087fd5e6e3%40googlegroups.com.
[ansible-project] Re: Ansible Split JSON Return
Ok, try this then: - debug: msg: "{{ item.mac-address }}" loop: "{{ mdb.json }}" On Thursday, March 5, 2020 at 10:45:03 AM UTC-5, David Foley wrote: > > - > - hosts: localhost > gather_facts: false > tasks: > - name: Getting Mac Address > uri: > url: http://.com > return_content: yes > > register: mdb > - debug: > msg: "{{ mdb.json }}" > > > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0fcc3dce-712d-45df-a1d4-95c3848493db%40googlegroups.com.
[ansible-project] Re: Ansible Split JSON Return
What's your plabook look like? You'll probably have to loop through your JSON results as it looks like it's a list. On Thursday, March 5, 2020 at 10:34:40 AM UTC-5, David Foley wrote: > > When i do Both > > "{{ mdb.json.mac-address }}" > "{{ mdb.json.split(':')[1:6] | join(':') }}" > > It returns > > fatal: [localhost]: FAILED! => {"msg": "The task includes an option with > an undefined variable. The error was: 'list object' has no attribute > 'mac'\n\nThe error appears to be in '/srv/Ansible/mdb.yaml': line 8, column > 5, but may\nbe elsewhere in the file depending on the exact syntax > problem.\n\nThe offending line appears to be:\n\nregister: mdb\n - > debug:\n^ here\n"} > > fatal: [localhost]: FAILED! => {"msg": "The task includes an option with > an undefined variable. The error was: 'list object' has no attribute > 'split'\n\nThe error appears to be in '/srv/Ansible/mdb.yaml': line 8, > column 5, but may\nbe elsewhere in the file depending on the exact syntax > problem.\n\nThe offending line appears to be:\n\nregister: mdb\n - > debug:\n^ here\n"} > > > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7aa61efa-1cf0-4604-9b7a-bd30d6349c9f%40googlegroups.com.
[ansible-project] Re: Ansible Split JSON Return
Something like this would work I believe: "{{ mdb.json.split(':')[1:6] | join(':') }}" Also, could you not just reference it directly by using "{{ mdb.json.mac-address }}"? On Thursday, March 5, 2020 at 9:52:52 AM UTC-5, David Foley wrote: > > Have the Following Playbook Which Returns the following > > ok: [localhost] => { > "mdb.json": [ > { > "mac-address": "xx:xx:xx:xx:xx" > } > ] > } > > > -- > - hosts: localhost > gather_facts: false > tasks: > - name: Getting Mac Address > uri: url="http://.com?field=mac-address; return_content=yes > register: mdb > - debug: > msg: "{{ mdb.json.split(':') }}" > > What i would like to Return is just > > "msg": "xx:xx:xx:xx:xx" > > But Split doesn't seem to work > > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0776c9b4-d5fd-439c-bdb9-ac1ef03425db%40googlegroups.com.
Re: [ansible-project] Re: Testing Authentication with Ansible
Circling back around to this. What do you mean by crawlers? Any you'd recommend. I did notice the URI module can pass credentials to a site, but when I try that it works with any credentials, even non-existent or incorrect credentials, so I'm not totally sure what that is actually doing because it can't be correctly authenticating. On Thursday, December 5, 2019 at 11:17:40 AM UTC-5, Stefan Hornburg (Racke) wrote: > > On 12/5/19 3:20 PM, Adam wrote: > > We've been experimenting using Selenium for things like this. It's not > simple and will probably make your head hurt (it > > makes mine hurt), but it is very flexible for things like this. > > There are numerous crawlers around that can be used for that task if you > can't stomach Selenium. > > Regards > Racke > > > > > On Wednesday, December 4, 2019 at 3:16:13 PM UTC-5, Cade Lambert wrote: > > > > We have a CMS web application that we'd like to ensure is up and > accessible. I was using the URI module to check > > the login page for a proper response code, but I'd like to go a step > further and test that a set of credentials can > > actually log into the site. I've tried messing around with some of > the examples on the URI module documentation to > > no avail. Has anyone done something like this before? > > > > -- > > 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 > > ansible...@googlegroups.com ansible-project+unsubscr...@googlegroups.com >. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/ansible-project/27263f7e-0bda-46d7-a9a4-64641b06bb33%40googlegroups.com > > > < > https://groups.google.com/d/msgid/ansible-project/27263f7e-0bda-46d7-a9a4-64641b06bb33%40googlegroups.com?utm_medium=email_source=footer>. > > > > > -- > Ecommerce and Linux consulting + Perl and web application programming. > Debian and Sympa administration. Provisioning with Ansible. > > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/668ba131-18c8-4e56-8177-aa919d83e933%40googlegroups.com.
[ansible-project] Testing Authentication with Ansible
We have a CMS web application that we'd like to ensure is up and accessible. I was using the URI module to check the login page for a proper response code, but I'd like to go a step further and test that a set of credentials can actually log into the site. I've tried messing around with some of the examples on the URI module documentation to no avail. Has anyone done something like this before? -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0db8d37c-1e45-4a85-9486-802321d17c4a%40googlegroups.com.
Re: [ansible-project] Variable Not Recognized as Integer
- name: Get host ID uri: url: https://satellite/api/v2/inventories/18/hosts/ method: GET body_format: json force_basic_auth: yes user: "{{ tower_user }}" password: "{{ tower_pass }}" validate_certs: no status_code: 200 register: host_list when: inventory_action == 'Remove Host' - set_fact: host_id: "{{ host_list.json.results|json_query(query)|int }}" vars: query: "[?name=='{{ host_name }}'].id" when: inventory_action == 'Remove Host' - debug: msg: "{{ host_id[0]| int }}" when: inventory_action == 'Remove Host' #I added [0] to the host_id variable to remove the brackets from the json output. - name: Remove server from, Tower inventory uri: url: https://satellite/api/v2/inventories/18/hosts/ method: POST body: id: "{{ host_id[0]|int }}" disassociate: true body_format: json force_basic_auth: yes user: "{{ tower_user }}" password: "{{ tower_pass }}" validate_certs: no status_code: 204 when: inventory_action == 'Remove Host' I have it filtered where host_id is set, and filtered where it's used in the API call, and I'm getting the same error. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9a4cd798-de94-494d-ae02-92d48a205ee8%40googlegroups.com.
[ansible-project] Variable Not Recognized as Integer
I'm attempting to use the Tower API to remove a host from an inventory. Here's the tasks in my playbook: - name: Get host ID uri: url: https://satellite/api/v2/inventories/18/hosts/ method: GET body_format: json force_basic_auth: yes user: "{{ tower_user }}" password: "{{ tower_pass }}" validate_certs: no status_code: 200 register: host_list when: inventory_action == 'Remove Host' - set_fact: host_id: "{{ host_list.json.results|json_query(query) }}" vars: query: "[?name=='{{ host_name }}'].id" when: inventory_action == 'Remove Host' - debug: msg: "{{ host_id[0]| int }}" when: inventory_action == 'Remove Host' #I added [0] to the host_id variable to remove the brackets from the json output. - name: Remove server from, Tower inventory uri: url: https://satellite/api/v2/inventories/18/hosts/ method: POST body: id: "{{ host_id[0] }}" disassociate: true body_format: json force_basic_auth: yes user: "{{ tower_user }}" password: "{{ tower_pass }}" validate_certs: no status_code: 204 when: inventory_action == 'Remove Host' Results: PLAY [localhost] TASK [Add server to Tower inventory] skipping: [localhost] TASK [Get host ID] ** ok: [localhost] TASK [set_fact] * ok: [localhost] TASK [debug] ok: [localhost] => { "msg": "813" } TASK [Remove server from, Tower inventory] ** fatal: [localhost]: FAILED! => {"allow": "GET, POST, HEAD, OPTIONS", "changed": false, "connection": "close", "content": "{\"msg\":\"\\\"id\\\" field must be an integer.\"}", "content_language": "en", "content_length": "42", "content_type": "application/json", "date": "Tue, 10 Sep 2019 13:47:41 GMT", "elapsed": 0, "json": {"msg": "\"id\" field must be an integer."}, "msg": "Status code was 400 and not [204]: HTTP Error 400: Bad Request", "redirected": false, "server": "nginx/1.14.1", "status": 400, "url": "https://satellite/api/v2/inventories/18/hosts/;, "vary": "Accept, Accept-Language, Cookie, Origin", "x_api_node": "localhost", "x_api_time": "0.100s", "x_api_total_time": "0.122s"} PLAY RECAP ** localhost : ok=3changed=0unreachable=0 failed=1skipped=1rescued=0ignored=0 I've tried casting to int using '| int' on the host_id variable but I still get that "field must be an integer" error. Any ideas? -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ca6e80ee-d61a-4f22-a844-be7e192eaa25%40googlegroups.com.
[ansible-project] Re: ansible and windows laptops on corporate and wan networks
I would think the only solution would be for them to access a corporate VPN when they are on anything outside the internal corporate network. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/69ff58c5-6835-438e-b128-3ef5851b9895%40googlegroups.com.
Re: [ansible-project] Re: Ansible and Satellite 6.4 - Waiting for Promote To Finish
Interesting, I'll try that later. For now, I just went ahead and created the role with each lifecycle environment having it's own register task and then importing a separate task file that contains the tasks to query the task queue in satellite and wait until the task is finished.. I think if I combined that with your idea, it'd probably work and have less code. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e4855998-4d63-4c2c-a7ed-4e3c3dee7e5f%40googlegroups.com.
Re: [ansible-project] Re: Ansible and Satellite 6.4 - Waiting for Promote To Finish
I tested that just now. It doesn't work. The API doesn't send a response about the status of the promote task. When I make the call to promote, it immediately responds with info that it started, and that's all. So the solution Kai provided really just keeps sending the same API request using the same loop item, because it never gets a response back from the API about result. root@tower /etc/ansible/playbooks $ ansible-playbook test.yml PLAY [localhost] TASK [Gathering Facts] ** ok: [localhost] TASK [Promote new RHEL7 version to Lifecycle Environments] ** FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (10 retries left). FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (9 retries left). FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (8 retries left). FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (7 retries left). FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (6 retries left). FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (5 retries left). FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (4 retries left). FAILED - RETRYING: Promote new RHEL7 version to Lifecycle Environments (3 retries left). -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4a97a600-72be-40eb-a712-b637736978d6%40googlegroups.com.
[ansible-project] Re: Ansible and Satellite 6.4 - Waiting for Promote To Finish
Yeah, it's not defined because it's not a value that's returned when the API call is sent. I'm not sure there's a way to do what I'm trying to do with a loop. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2ec91a91-ced2-4c58-9380-b343b6b3acf8%40googlegroups.com.
[ansible-project] Re: Sending output from a completed job via the mail module
tower_id would be the job id for the job in which the template was run, so you need to pull that job id from somewhere. So basically, yeah, you'd have to create a new playbook to kick off the playbook you want to email the results on. Unfortunately, I'm short on time currently but here's the outline of what I'd do. It might not be the slickest way but it'd work. 1. API request to run template: https://docs.ansible.com/ansible-tower/3.5.0/html/towerapi/api_ref.html#/Job_Templates/Job_Templates_job_templates_launch_create - register the results into a job_run 2. Use the results from job_run to get the job id. Throw it into a debug task if you need to see the output of job_run. Usually it's something like job_run.results.id 3. API request to get the output from the job, using the job id: https://docs.ansible.com/ansible-tower/3.5.0/html/towerapi/api_ref.html#/Jobs/Jobs_jobs_read_0 - register the results into job_results 4. Use the mail module to email the contents of job_results -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/710fad28-a00e-4c9d-8ded-0b60ace6bde1%40googlegroups.com.
[ansible-project] Re: Sending output from a completed job via the mail module
Couple of things: 1. Ansible has a uri module for API calls, it'll do the same thing but best practice is to use a module if there's one available. 2. Where are you getting tower_id from? It looks like it's undefined. 3. Are you kicking the template off with an API call too? That'd be the best way, then register the results and parse out the job ID from those results. Something like - API call to initiate template and register results into variable1 - API call to get the job output, using the variable to parse the job ID, then register those results to variable2 - Mail module to email the contents of variable2 -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/663a4c04-4f6c-46a0-879c-7b8b45b8af86%40googlegroups.com.
Re: [ansible-project] Ansible and Satellite 6.4 - Waiting for Promote To Finish
So I'm still having trouble with this. Here's my task: - name: Promote new RHEL7 version to Lifecycle Environments uri: url: "https://satellite/katello/api/v2/content_view_versions/{{ (content_views7.json.results[0].id | int) }}/promote" method: POST body: description: "Promoted by Tower" environment_id: "{{ item }}" organization_id: 3 force: true user: "{{ satellite_user }}" password: "{{ satellite_pass }}" force_basic_auth: yes validate_certs: no body_format: json status_code: 202 register: promote_rhel7 loop: - 3 - 4 - 5 - 6 - 7 - 8 until: promote_rhel7.json.result == 'success' retries: 10 delay: 20 I tried this but it error'd out with: fatal: [localhost]: FAILED! => {"msg": "The conditional check 'promote_rhel7.json.result == 'success'' failed. The error was: error while evaluating conditional (promote_rhel7.json.result == 'success'): 'dict object' has no attribute 'result'"} Which I kind of expected because it doesn't seem like it's returning anything. I'm trying to loop through all the lifecycle environments in one task, but I also need to check the tasks from satellite to ensure the promotion is done before it attempts to promote to the next lifecycle environment, or it'll throw a lock error. I know I could ditch the loop and create a task for each lifecycle environment, and check satellite tasks prior to each promotion, but I was hoping there was a sleeker way to do it. I've used loop_control and pause previously, but I'd like to know for certain a promote is complete before attempting the next one. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6251fc3b-aac7-4e63-8e5a-a6a840da0ecc%40googlegroups.com.
[ansible-project] Re: Thoughts on Dynamic Variables
Awesome, thanks for the responses. This definitely looks like a more logical, thoughtful approach than cramming a bunch of if-else statements into a single line. I'll take these back and try reworking my vars file. Thanks again. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/cf61bb3d-90d6-4f55-9e24-dada47412dfd%40googlegroups.com.
[ansible-project] Re: Thoughts on Dynamic Variables
The problem I come across is I'll need logic to decide on the content of a variable and that logic will turn into a long string. For example, when determining which users to add to a system, we might have a variable like: user_list: "{{ 'user1,user2,user3' if server_type=db_server else 'user4,user5,user6' if server_type=web_server else 'user7,user8,user1' if server_type=standard_server }}' These can get pretty long depending on what we're trying to do, and fairly hard to read. I could do multi-line variables I guess, but was wondering if there's a more clever way to handle stuff like this. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/38a5d109-d789-465b-9694-470c0b6b59d7%40googlegroups.com.
Re: [ansible-project] chnaging all passwords on linux box
I think you should run through how you want it to work. Do you want it to output a file to a server? A workstation? Shared storage? Are you emailing the file to the user? If your intent is to email that file to a user, you could just use the email module and include the password variable in the body of the email. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/818c616f-aaf1-497b-9230-678ab980ae71%40googlegroups.com.
[ansible-project] Thoughts on Dynamic Variables
I wanted to see how you guys go about building dynamic variables. We have some playbooks/roles that require variables to be built based on various things, such as user input or other variables. I usually end up building a long line of 'if-then-else' statements, which can be difficult to read and troubleshoot. Is there a better way to go about this? How do you all tackle this? -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/564a4724-be29-4296-bcc5-2df8ce63f1be%40googlegroups.com.
[ansible-project] Re: Registering value from JSON output
Great, thanks for the help. -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/2bf6e43e-3da3-4fd6-8aa8-b4681e64caeb%40googlegroups.com.
[ansible-project] Re: Registering value from JSON output
Ah, ok, I missed that those were backticks. So because we used double-quotes to encompass the whole argument, and single-quotes to encompass the json_query argument, we cannot use single-quotes again to encompass the search string. We need to use something else, in this case backticks, to distinguish the search string? -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/abc5819a-4aec-47b8-9f91-113bd34e755a%40googlegroups.com.
[ansible-project] Re: Registering value from JSON output
Ok, I guess a little background would help. I'm using the uri module to retrieve a list of hosts in an inventory from our Tower server. It returns the JSON output below. I've paired it down to just the pieces I care about. There are two servers in this inventory. I'd like to retrieve the id based on the server name. ok: [localhost] => { "host_list.json.results": [ { "ansible_facts_modified": null, "created": "2019-08-27T18:50:09.132071Z", "description": "", "enabled": true, "has_active_failures": false, "has_inventory_sources": false, "id": 799, "insights_system_id": null, "instance_id": "", "inventory": 18, "last_job": null, "last_job_host_summary": null, "modified": "2019-08-27T18:50:09.132085Z", "name": "server1", }, { "ansible_facts_modified": "2019-08-28T14:41:17.846100Z", "created": "2019-08-26T19:28:55.187225Z", "description": "", "enabled": true, "has_active_failures": false, "has_inventory_sources": false, "id": 790, "insights_system_id": null, "instance_id": "", "inventory": 18, "last_job": 7879, "last_job_host_summary": 10273, "modified": "2019-08-28T14:41:17.846235Z", "name": "server2", } ] } I tried json_query: - set_fact: host_id: "{{ host_list.json.results|json_query('[?name == 'server2'].id') }}" It threw the following error: fatal: [localhost]: FAILED! => {"msg": "template error while templating string: expected token ',', got 'server2'. String: {{ host_list.json.results|json_query('[?name == 'server2'].id') }}"} On Tuesday, August 27, 2019 at 3:44:16 PM UTC-4, Cade Lambert wrote: > > I'm trying to register the value of a JSON object only when another JSON > object is equal to a certain value, but I just can't figure out how I'd do > that. > > For example, this is my JSON output which is registered in the variable > results_var: > > "output": { > "json": { > "results": [ > { > "name": "item1" > "id": "26" > } > { > "name": "item2" > "id": "29" > } > { > "name": "item3" > "id": "10" > } > ] >} > } > > What I'd like to do is place the id into a variable only when the name > matches a string. > > I was trying something like this but it fails because the variable is a > list. > > - set_fact: > host_id: "{{ item.id }}" > when: item.name == "item2" > loop: "{{ results_var.output.json.results }}" > > -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ea80493e-5075-40e2-ae52-3f5f3a8e8bce%40googlegroups.com.
[ansible-project] Registering value from JSON output
I'm trying to register the value of a JSON object only when another JSON object is equal to a certain value, but I just can't figure out how I'd do that. For example, this is my JSON output which is registered in the variable results_var: "output": { "json": { "results": [ { "name": "item1" "id": "26" } { "name": "item2" "id": "29" } { "name": "item3" "id": "10" } ] } } What I'd like to do is place the id into a variable only when the name matches a string. I was trying something like this but it fails because the variable is a list. - set_fact: host_id: "{{ item.id }}" when: item.name == "item2" loop: "{{ results_var.output.json.results }}" -- 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 ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a2c3746a-47a3-4e9f-b6fe-510e8841fe6e%40googlegroups.com.
Re: [ansible-project] uri Module - Wait For Satellite Task to Complete
I guess I was staring at this too long and was referencing the wrong variable, or I got lost in the JSON output of the results, but the answer ended up being task_result.json.result == 'success', which makes perfect sense. Now I just need to figure out how to do this, in a loop, for each lifecycle environment promotion. On Wednesday, June 12, 2019 at 1:26:26 PM UTC-4, Cade Lambert wrote: > > Got it, thanks for the explanation. I'll try that and see where it gets > me. > > On Wednesday, June 12, 2019 at 1:21:23 PM UTC-4, Matt Martz wrote: >> >> The idea, is that if `results` isn't defined, to provide a default for >> the until logic to complete. >> >> You are using `results[4]`, which means it's the 5th element (now I want >> to go watch a movie). >> >> Then in the 5th element of results, you are inspecting the `result` key, >> for a value of `success`. >> >> This just says when `results` is not defined, use the default of >> [0,1,2,3, dict(result='NOT_SUCCESS')] >> >> the 0-3 elements, are useless, and don't matter, it's just there to make >> sure that the 5th element ([4]) is a dict/hash that matches your >> expectations. >> >> On Wed, Jun 12, 2019 at 12:11 PM Cade Lambert wrote: >> >>> Can you explain what you're doing with the until line you posted? >>> >>> So I know what's in task_result.json.results[4].result. Here's what I >>> get if I debug as my next task: >>> >>> - debug: >>> var: tasks_list.json.results[4].result >>> >>> >>> TASK [debug] >>> ** >>> ok: [localhost] => { >>> "tasks_list.json.results[4].result": "success" >>> } >>> >>> That's why I'm confused, because according to that debug, the until line >>> should work. >>> >>> On Wednesday, June 12, 2019 at 12:38:06 PM UTC-4, Matt Martz wrote: >>>> >>>> You can, but the error is telling you that the JSON response, didn't >>>> have a `results` key. You need to account for the fact, that you might >>>> not >>>> always get the response you expect. >>>> >>>> Maybe like: >>>> >>>> until: (task_result.json.results|default([0, 1, 2, 3, >>>> dict(result='NOT_SUCCESS')))[4].result == 'success' >>>> >>>> In any case, your until makes a lot of assumptions about the data you >>>> expect to be there, you need to work from the perspective of not having >>>> what you expect. >>>> >>>> On Wed, Jun 12, 2019 at 11:14 AM Cade Lambert wrote: >>>> >>>>> I'm writing a playbook to publish new Content View versions and >>>>> promote the new version to our Lifecycle Environments using the uri >>>>> module. I'm trying to create a task that will query the task ID until it >>>>> reports a result of 'success'. I've tried the following: >>>>> >>>>> - name: Get the tasks list from Satellite >>>>> uri: >>>>> url: https://satelitlite-server/foreman_tasks/api/tasks >>>>> method: GET >>>>> body: >>>>> order: 'id DESC' >>>>> organization_id: 3 >>>>> user: "{{ satellite_user }}" >>>>> password: "{{ satellite_pass }}" >>>>> force_basic_auth: yes >>>>> validate_certs: no >>>>> body_format: json >>>>> register: tasks_list >>>>> >>>>> - name: Wait for new Content View version to finish publishing >>>>> uri: >>>>> url: "https://satellite-server/foreman_tasks/api/tasks/{{ >>>>> tasks_list.json.results[4].id }}" >>>>> method: GET >>>>> status_code: 200 >>>>> validate_certs: no >>>>> user: "{{ satellite_user }}" >>>>> password: "{{ satellite_pass }}" >>>>> force_basic_auth: yes >>>>> body_format: json >>>>> register: task_result >>>>> until: task_result.json.results[4].result == 'success' >>>>> retries: 60 >>>>> delay
Re: [ansible-project] uri Module - Wait For Satellite Task to Complete
Got it, thanks for the explanation. I'll try that and see where it gets me. On Wednesday, June 12, 2019 at 1:21:23 PM UTC-4, Matt Martz wrote: > > The idea, is that if `results` isn't defined, to provide a default for the > until logic to complete. > > You are using `results[4]`, which means it's the 5th element (now I want > to go watch a movie). > > Then in the 5th element of results, you are inspecting the `result` key, > for a value of `success`. > > This just says when `results` is not defined, use the default of [0,1,2,3, > dict(result='NOT_SUCCESS')] > > the 0-3 elements, are useless, and don't matter, it's just there to make > sure that the 5th element ([4]) is a dict/hash that matches your > expectations. > > On Wed, Jun 12, 2019 at 12:11 PM Cade Lambert > wrote: > >> Can you explain what you're doing with the until line you posted? >> >> So I know what's in task_result.json.results[4].result. Here's what I get >> if I debug as my next task: >> >> - debug: >> var: tasks_list.json.results[4].result >> >> >> TASK [debug] >> ** >> ok: [localhost] => { >> "tasks_list.json.results[4].result": "success" >> } >> >> That's why I'm confused, because according to that debug, the until line >> should work. >> >> On Wednesday, June 12, 2019 at 12:38:06 PM UTC-4, Matt Martz wrote: >>> >>> You can, but the error is telling you that the JSON response, didn't >>> have a `results` key. You need to account for the fact, that you might not >>> always get the response you expect. >>> >>> Maybe like: >>> >>> until: (task_result.json.results|default([0, 1, 2, 3, >>> dict(result='NOT_SUCCESS')))[4].result == 'success' >>> >>> In any case, your until makes a lot of assumptions about the data you >>> expect to be there, you need to work from the perspective of not having >>> what you expect. >>> >>> On Wed, Jun 12, 2019 at 11:14 AM Cade Lambert wrote: >>> >>>> I'm writing a playbook to publish new Content View versions and promote >>>> the new version to our Lifecycle Environments using the uri module. I'm >>>> trying to create a task that will query the task ID until it reports a >>>> result of 'success'. I've tried the following: >>>> >>>> - name: Get the tasks list from Satellite >>>> uri: >>>> url: https://satelitlite-server/foreman_tasks/api/tasks >>>> method: GET >>>> body: >>>> order: 'id DESC' >>>> organization_id: 3 >>>> user: "{{ satellite_user }}" >>>> password: "{{ satellite_pass }}" >>>> force_basic_auth: yes >>>> validate_certs: no >>>> body_format: json >>>> register: tasks_list >>>> >>>> - name: Wait for new Content View version to finish publishing >>>> uri: >>>> url: "https://satellite-server/foreman_tasks/api/tasks/{{ >>>> tasks_list.json.results[4].id }}" >>>> method: GET >>>> status_code: 200 >>>> validate_certs: no >>>> user: "{{ satellite_user }}" >>>> password: "{{ satellite_pass }}" >>>> force_basic_auth: yes >>>> body_format: json >>>> register: task_result >>>> until: task_result.json.results[4].result == 'success' >>>> retries: 60 >>>> delay: 20 >>>> >>>> This gives me an error of: >>>> >>>> TASK [Wait for new Content View version to finish publishing] >>>> * >>>> fatal: [localhost]: FAILED! => {"msg": "The conditional check >>>> 'task_result.json.results[4].result == 'success'' failed. The error was: >>>> error while evaluating conditional (task_result.json.results[4].result == >>>> 'success'): 'dict object' has no attribute 'results'"} >>>> >>>> I'm guessing I can't query a variabl
Re: [ansible-project] uri Module - Wait For Satellite Task to Complete
Can you explain what you're doing with the until line you posted? So I know what's in task_result.json.results[4].result. Here's what I get if I debug as my next task: - debug: var: tasks_list.json.results[4].result TASK [debug] ** ok: [localhost] => { "tasks_list.json.results[4].result": "success" } That's why I'm confused, because according to that debug, the until line should work. On Wednesday, June 12, 2019 at 12:38:06 PM UTC-4, Matt Martz wrote: > > You can, but the error is telling you that the JSON response, didn't have > a `results` key. You need to account for the fact, that you might not > always get the response you expect. > > Maybe like: > > until: (task_result.json.results|default([0, 1, 2, 3, > dict(result='NOT_SUCCESS')))[4].result == 'success' > > In any case, your until makes a lot of assumptions about the data you > expect to be there, you need to work from the perspective of not having > what you expect. > > On Wed, Jun 12, 2019 at 11:14 AM Cade Lambert > wrote: > >> I'm writing a playbook to publish new Content View versions and promote >> the new version to our Lifecycle Environments using the uri module. I'm >> trying to create a task that will query the task ID until it reports a >> result of 'success'. I've tried the following: >> >> - name: Get the tasks list from Satellite >> uri: >> url: https://satelitlite-server/foreman_tasks/api/tasks >> method: GET >> body: >> order: 'id DESC' >> organization_id: 3 >> user: "{{ satellite_user }}" >> password: "{{ satellite_pass }}" >> force_basic_auth: yes >> validate_certs: no >> body_format: json >> register: tasks_list >> >> - name: Wait for new Content View version to finish publishing >> uri: >> url: "https://satellite-server/foreman_tasks/api/tasks/{{ >> tasks_list.json.results[4].id }}" >> method: GET >> status_code: 200 >> validate_certs: no >> user: "{{ satellite_user }}" >> password: "{{ satellite_pass }}" >> force_basic_auth: yes >> body_format: json >> register: task_result >> until: task_result.json.results[4].result == 'success' >> retries: 60 >> delay: 20 >> >> This gives me an error of: >> >> TASK [Wait for new Content View version to finish publishing] >> * >> fatal: [localhost]: FAILED! => {"msg": "The conditional check >> 'task_result.json.results[4].result == 'success'' failed. The error was: >> error while evaluating conditional (task_result.json.results[4].result == >> 'success'): 'dict object' has no attribute 'results'"} >> >> I'm guessing I can't query a variable that's registered in the same >> task? Does anyone know an alternative method other than just pausing the >> playbook for a few minutes to let the publish task finish? >> >> -- >> 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 ansible...@googlegroups.com . >> To post to this group, send email to ansible...@googlegroups.com >> . >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/ansible-project/6f35ca5c-1c4c-439c-bf05-42a5ad6fe478%40googlegroups.com >> >> <https://groups.google.com/d/msgid/ansible-project/6f35ca5c-1c4c-439c-bf05-42a5ad6fe478%40googlegroups.com?utm_medium=email_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Matt Martz > @sivel > sivel.net > -- 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 ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7c683512-75d6-4707-9689-d76f522adc6a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Re: How to get details about a user running an Ansible Tower job
Tower returns a handful of variables containing info about a job execution: https://docs.ansible.com/ansible-tower/latest/html/userguide/job_templates.html - tower_job_id: The Job ID for this job run - tower_job_launch_type: The description to indicate how the job was started: - *manual*: Job was started manually by a user. - *relaunch*: Job was started via relaunch. - *callback*: Job was started via host callback. - *scheduled*: Job was started from a schedule. - *dependency*: Job was started as a dependency of another job. - *workflow*: Job was started from a workflow job. - *sync*: Job was started from a project sync. - *scm*: Job was created as an Inventory SCM sync. - tower_job_template_id: The Job Template ID that this job run uses - tower_job_template_name: The Job Template name that this job uses - tower_user_id: The user ID of the Tower user that started this job. This is not available for callback or scheduled jobs. - tower_user_name: The user name of the Tower user that started this job. This is not available for callback or scheduled jobs. - tower_schedule_id: If applicable, the ID of the schedule that launched this job - tower_schedule_name: If applicable, the name of the schedule that launched this job - tower_workflow_job_id: If applicable, the ID of the workflow job that launched this job - tower_workflow_job_name: If applicable, the name of the workflow job that launched this job. Note this is also the same as the workflow job template. Is this what you're looking for? On Sunday, June 9, 2019 at 12:47:32 PM UTC-4, Dmitrii M wrote: > > Hi all, > > I've two questions: > > > 1) Is there a way to know the details about a user who runs playbooks (job > template/workflow)? I'd propose that module "tower_user" might do that, it > just can be extended with some output like it does "stat" module. > > ## playbook.yml > > - tower_user: > username: jobowner > register: jobowner_stat > > - debug: > msg: | > Username: {{ jobowner_stat.username }} > Email: {{ jobowner_stat.email }} > Is_superuser: {{ jobowner_stat.superuser }} > First name: {{ jobowner_stat.first_name }} > Last name: {{ jobowner_stat.last_name }} > > Or if there is something already implemented, it would be great to know > about this. > > 2) How can I know that a playbook is run by Ansible Tower? For example, > I'm writing a playbook on a local machine and I need to run additional > tasks like "Get the owner of a job which runs the playbook" above. > > > Thank you, > Dmitrii > > > -- 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 ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1610490a-64fe-4417-a2d4-14ddd2ed97a4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Re: tower ansible template: how to pass parameters to a python script
We used the expect module for this. For your example, it'd look something like this: --- - hosts: ISE connection: local args: tasks: - script: /usr/bin/python3 ../scripts/ise_add.py register: output On Monday, June 10, 2019 at 10:45:21 AM UTC-4, Gilles wrote: > > I am using a template to run a python script. This works fine. > > --- >> - hosts: ISE >> connection: local >> args: >> tasks: >> - script: /usr/bin/python3 ../scripts/ise_add.py >> register: output >> >> - debug: var=output.stdout_lines >> >> >> >> > Now I would like to pass 2 parameters to the python script (hostname and > ipaddress), either harcoded or from any file or any variable. > May I use the "extra variables" section of the template panel? > Do I have to use Jinja2? > > Thanks > Regards, > Gilles > > > -- 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 ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/69aa184f-be9c-410e-b019-eba8825ed4e0%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] uri Module - Wait For Satellite Task to Complete
I'm writing a playbook to publish new Content View versions and promote the new version to our Lifecycle Environments using the uri module. I'm trying to create a task that will query the task ID until it reports a result of 'success'. I've tried the following: - name: Get the tasks list from Satellite uri: url: https://satelitlite-server/foreman_tasks/api/tasks method: GET body: order: 'id DESC' organization_id: 3 user: "{{ satellite_user }}" password: "{{ satellite_pass }}" force_basic_auth: yes validate_certs: no body_format: json register: tasks_list - name: Wait for new Content View version to finish publishing uri: url: "https://satellite-server/foreman_tasks/api/tasks/{{ tasks_list.json.results[4].id }}" method: GET status_code: 200 validate_certs: no user: "{{ satellite_user }}" password: "{{ satellite_pass }}" force_basic_auth: yes body_format: json register: task_result until: task_result.json.results[4].result == 'success' retries: 60 delay: 20 This gives me an error of: TASK [Wait for new Content View version to finish publishing] * fatal: [localhost]: FAILED! => {"msg": "The conditional check 'task_result.json.results[4].result == 'success'' failed. The error was: error while evaluating conditional (task_result.json.results[4].result == 'success'): 'dict object' has no attribute 'results'"} I'm guessing I can't query a variable that's registered in the same task? Does anyone know an alternative method other than just pausing the playbook for a few minutes to let the publish task finish? -- 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 ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6f35ca5c-1c4c-439c-bf05-42a5ad6fe478%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.