[ansible-project] Re: Problem looping over JSON data returned from URI call
Try using from_json filter http://docs.ansible.com/ansible/playbooks_filters.html#filters-for-formatting-data https://gist.github.com/lxhunter/45fb119c0128600158d8 On Tuesday, November 17, 2015 at 12:09:30 PM UTC-6, Andris Bjornson wrote: > > Hello - I have a question about looping over json data I’ve received from > calling a REST api using the URI module. I’ve been tearing my hair out > over the last several days trying to sort this out…and have googled > extensively - but haven’t gotten anywhere. I think it has to do with the > difference between a dict, and array, and a list…but i’m new-ish to ansible > and not understanding what i’m doing wrong. Any help greatly appreciated. > > Here is the data returned and registered by the URI module call. Lets say > I registered it in a variable called "registered_variable" > https://gist.github.com/andris/77dcdfd17eef0cdd3563 > > I can access individual items from the array by doing this: > registered_variable.json.data[1] > > I can access attributes of individual items from the array by doing this: > registered_variable.json.data[1].name > > But whenever I try to use with_dict or with_items to loop over > registered_variable.json.dataI just get an "item is undefined error" > (for example) > > - debug: > msg: "{{item.name}} is the name of the device" > with_dict: "{{registered_variable.json.data}}" > > I also tried first storing the object in a variable first: > > - set_fact: > devices: "{{ registered_variable.json.data }}" > - debug: > msg: "{{item.name}} is the device name" > with_dict: devices > > > I am running on the latest dev from checkout (2.0.0) > > Any suggestions? > > Thanks in advance! > -- 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/d96a03d4-4964-46dc-bf1c-38f950314dbb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] YAML syntax error (beginner)
While this may not be the cause of your issues, the following is (or will be) an issue for you. - name: ensure joe is installed yum apt: name=joe state=latest when: ansible_os_family == CentOS or ansible_os_family == Fedora change to: - name: ensure joe is installed yum yum: name=joe state=latest when: ansible_os_family == CentOS or ansible_os_family == Fedora On Friday, April 11, 2014 11:06:48 AM UTC-5, James Tanner wrote: On 04/11/2014 03:20 AM, WS wrote: Hello I just started to use ansible so please bear with me. I managed to run a few basic playbooks but I am stuck with the following one (basic as well): --- - hosts: all tasks: - name: copy bashrc to .bashrc action: copy src=files/bashrc dest=~root/.bashrc backup=yes - name: copy bashrc to .bash_profile action: copy src=files/bashrc dest=~root/.bash_profile backup=yes - name: ensure joe is installed apt apt: pkg=joe state=latest update_cache=yes when: ansible_os_family == Debian - name: ensure joe is installed yum apt: name=joe state=latest when: ansible_os_family == CentOS or ansible_os_family == Fedora I get the following error when running it: ERROR: Syntax Error while loading YAML script, commonconfig.yml Note: The error may actually appear before this position: line 7, column 1 - name: copy bashrc to .bash_profile action: copy src=files/bashrc dest=~root/.bash_profile backup=yes The script runs fine when there is only one name/action pair (the first one). Sorry if this is obvious but I am just starting with YAML. -- 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-proje...@googlegroups.com javascript:. To post to this group, send email to ansible...@googlegroups.comjavascript: . To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4e2abd33-13a7-4489-97eb-8ac4f8e6310f%40googlegroups.comhttps://groups.google.com/d/msgid/ansible-project/4e2abd33-13a7-4489-97eb-8ac4f8e6310f%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. It seems like the error is pointing out that action: is not aligned with name: I'm not sure what editor you are using but perhaps you could replace all tabs with spaces and then make sure things are lined up correctly. http://stackoverflow.com/questions/11094383/how-can-i-convert-tabs-to-spaces-in-every-file-of-a-directory -- 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/320d70dc-b234-49b5-b4b2-eae3554398d9%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] Ansible conditions and logics
I've never seen this syntax used with when: - name: Moving on debug: msg=doing something with {{ item.item }} when: - item.stat.exists == true - item.stat.islnk != true with_items: st.results Is that a valid conditional? Is it equivalent to 'and' ? On Wednesday, April 2, 2014 5:53:52 AM UTC-5, Maxim Odinintsev wrote: Hello, I'm tried make it over ansible, but in final, i think much easiest way is using script module. If someone interesting, when i tried it, i'm used this construction for getting files attributes and states: - name: Getting files stats stat: path={{ item }} register: st with_items: - /etc/asterisk - /etc/bind - /etc/GeoIP.conf - /etc/iptables - /etc/jabber - /etc/monit - /etc/mysql - /etc/nginx - /etc/postfix - /etc/ppp - /etc/snmp - /etc/sphinx - /etc/xl2tpd - name: Moving on debug: msg=doing something with {{ item.item }} when: - item.stat.exists == true - item.stat.islnk != true with_items: st.results Thank you Hello, Yes, you understand correctly. How can I synchronize files on remote node (not from local host to remote) ? Thank you. If I understand correctly, you're copying the contents of several directories to a central location, removing the old path, and then creating a symlink to the new location? To do that with ansible you'd just need to call the synchronize module to copy the files (or use command/shell to do the rsync), and then use the file module to create the symlink. On Mon, Mar 31, 2014 at 6:56 AM, Maxim Odinintsev gwyn...@gmail.comwrote: Hello, I'm trying migrate out my infrastructure under ansible control, but stopped on simple things realization with ansible. I would be very grateful if some one can explain, best way for moving on this simple shell script under ansible. May be simplest way is running external shell, and not try to push it all under ansible logic ? pushd / for i in \ /etc/ipsec* \ /home \ /root \ do [[ -r $i ]] || continue [[ -L $i ]] continue dst_dir=$(readlink -m /protected$(dirname $i)) dst_name=${dst_dir}/$(basename $i) mkdir -p $dst_dir rsync -a $i $dst_dir rm -rf $i ln -s $dst_name $i ls -ld $i done popd Thank you -- 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-proje...@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/a29d1d41-ffd3-40e9-8cc4-a4a891e443c6%40googlegroups.comhttps://groups.google.com/d/msgid/ansible-project/a29d1d41-ffd3-40e9-8cc4-a4a891e443c6%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- 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/bbf07a56-63bb-41d5-9c4a-d5185b123603%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Re: Delegated cronjobs with time vars per target host
Where are you using the rsnap_daily_hour variable? The task you pasted doesn't have it included. The vars file you included is host specific for 'newhost', if you are trying to use those variables in a play involving the backuphost (not a delegated_to task), you'll either need to use hostvars or restructure your variables in a different manner. So, using hostvars, accessing rsnap_daily_hour in a play on backuphost would be {{ hostvars['newhost']['rsnap_daily_hour'] }}. If it was me, I'd use group_vars with separate groups for each time slot, and then make the backuphost a member of each time slot group. That may or may not scale well, but I try to avoid using hostvars if at all possible. I'd change my mind if I was in an environment absolutely destined to remain small stable of course. Brian On Wednesday, April 2, 2014 6:29:09 PM UTC-5, Martin Božič wrote: Hi, I want to dynamically every new host to the backup server with rsnapshot. I have no problems putting SSH keys on backup target hosts and putting a template and exclude config for the target host into /etc/rsnapshot.d on backup host. The problem is when I try to add the rsnapshot cronjob for the new host. And here's the trick - I'm trying to add different times for each host because I don't want them to all hit the backup disk at the same time. So I figured I could put several cron time vars for each host in host_vars/ directory. Here's an example of what I'm trying to pull-off with cron module: FILE: roles/common/backup.yml - - name: weekly rsnapshot cron cron: name=rsnap {{ ansible_fqdn }} (upravlja Ansible) weekday={{ rsnap_weekly_day }} hour={{ rsnap_weekly_hour }} minute={{ rsnap_weekly_min }} user=root job=rsnapshot -c /etc/rsnapshot.d/{{ ansible_fqdn }}.conf weekly cron_file=rsnap-{{ ansible_fqdn }} delegate_to: backuphost FILE: host_vars/newhost rsnap_hourly_min: 12 rsnap_daily_min: 45 rsnap_daily_hour: 1 rsnap_weekly_min: 30 rsnap_weekly_hour: 21 rsnap_weekly_day: 3 What happens is that backuphost picks up the var of newhost and then cries foul: fatal: [backuphost] = One or more undefined variables: 'rsnap_daily_hour' is undefined I'm running out of ideas how I could do it. I've looked into several loops but I'm still a beginner with Ansible and YAML syntax, so if anyone has any idea how this delegation could work I'd really appreciate it! Regards, Martin -- 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/a6e47e28-59ff-428c-9407-e8d38b1fb96e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Re: Rebooting the server
If the server is taking a longer than the default timeout value, increase that value. Default is 300 seconds, might need to increase that. http://docs.ansible.com/wait_for_module.html Or there could be a connectivity issue. Is it listening on port 22? Does FQDN name resolution work? On Friday, March 28, 2014 9:00:28 AM UTC-5, Rafał Hajduk wrote: Hello I want to reboot my server and continue with other instructions. My code is: - name: reboot command: reboot notify: - wait until rebooted - name: wait until rebooted local_action: wait_for host={{ansible_fqdn}} port=22 state=started delay =30 sudo: false After execution I get an error: failed: [xxx] = {elapsed: 300, failed: true, item: } msg: Timeout when waiting for myhostname:22 FATAL: all hosts have already failed -- aborting How can I fix it? -- 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/23fe5fd2-c9e9-4ab5-91c3-4ab1b532d247%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Re: Rebooting the server
What entry is in your inventory host file? Is it IP address, short hostname, fqdn? The following variables are valid in your playbook, and the 'right' one depends on your environment. ansible_fqdn, ansible_hostname, inventory_hostname, inventory_hostname_short The ansible_fqdn and ansible_hostname are facts determined at the remote host. Inventory_hostname and inventory_hostname_short are parsed from your Ansible inventory file. For instance, in your current playbook, if you have an entry for the reboot target of dbserver, and for some reason the 'dbserver' node reports its fqdn as webserver.example.org then your reboot command will wait for webserver.example.org:22 to be available, which may not resolve from your Ansible management node. Given that Ansible has no problem connecting using the value in your inventory file, you might start with inventory_hostname which will use the entry in your inventory file. Relevant docs here: http://docs.ansible.com/playbooks_variables.html On Friday, March 28, 2014 10:28:06 AM UTC-5, Rafał Hajduk wrote: The server reboots very quickly (10-15 seconds), so timeout is not the issue. However the problem might be the FQDN name. I used it because I found it in some Ansible snippet. Which variable should I place there in order to get current host rebooted? (in my case it would be xxx) My hosts file: [xxx] xxx W dniu piątek, 28 marca 2014 16:13:27 UTC+1 użytkownik Brian Green napisał: If the server is taking a longer than the default timeout value, increase that value. Default is 300 seconds, might need to increase that. http://docs.ansible.com/wait_for_module.html Or there could be a connectivity issue. Is it listening on port 22? Does FQDN name resolution work? On Friday, March 28, 2014 9:00:28 AM UTC-5, Rafał Hajduk wrote: Hello I want to reboot my server and continue with other instructions. My code is: - name: reboot command: reboot notify: - wait until rebooted - name: wait until rebooted local_action: wait_for host={{ansible_fqdn}} port=22 state=started delay=30 sudo: false After execution I get an error: failed: [xxx] = {elapsed: 300, failed: true, item: } msg: Timeout when waiting for myhostname:22 FATAL: all hosts have already failed -- aborting How can I fix it? -- 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/4d6fe8fc-569c-45a4-9799-b4bfe4d5e4e1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Re: using one playbook to install two versions of a software in one run
You have to restructure the playbooks to loop within the role itself (perhaps have a list with versions to install in your variables), or call the role twice. I would really like to see some mechanism to loop over a role, but with that said, you should be able to find a solution. Why is calling the role twice not acceptable? I have a playbook that calls a role in 50 different ways, depending on how it's executed. While it's a bit long, it is structured simply, and easily understood. I had similar decisions to make, and looping within the role wasn't something I was happy with, so I ended up applying the role multiple times, which really isn't all that painful IMO. My problems with looping within the role (for my use case) was that I needed to use with_items for many tasks, which led to added complexity of the playbook - I understood perfectly what was required and being performed, but collaboration with other folks at my organization that are new to Ansible would prove difficult. On Tuesday, March 25, 2014 6:04:19 AM UTC-5, Prune wrote: For me the use case is : - I have a playbook that installs elasticsearch using a role - elasticsearch version is defined in the host file as a variable along each server name - I have a group with all the hosts needing elasticsearch Until then, we were using elasticsearch 0.90.x (x is 2,3 or 9). Now, I need to install BOTH the 0.90.x and the new 1.0.1 version at the same time. While the playbook can handle that, I can't find a way to have the role played twice, once for each version ? The only solution so far is calling the role twice and statically setting the version on each call, which is not acceptable. One solution would be to call the role using a with_item statement to have it run for every version is defined in a dict... but this is deprecated Any clue ? Thanks. Prune -- 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/3dae1e0d-38a3-497e-a72a-67d8a85f64d6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] group_by adding all hosts?
I ran into odd issues when using group names with hyphens in them. Similar situation of not using variable names with hyphens in them. Not sure if this is the case but its worth mentioning. -- 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/8bae4dee-31cb-4092-a2b2-7ff401efa5d4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Should move shell module from sh to bash?
Unless I'm missing something, can't you just set executable: /bin/bash ? -- 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. For more options, visit https://groups.google.com/groups/opt_out.
[ansible-project] Re: How would you set variables in this case?
How about keep your default variables in roles/vars/main.yml and then for variables that would be considered special case or overrides you put them elsewhere with higher precedence. For your RHEL 5 example, take a look at http://docs.ansible.com/playbooks_variables.html#conditional-imports and you could use something similar like vars/{{ ansible_lsb.id }}_{{ ansible_lsb.major_release }}.yml where you'd populate the RedHat_5.yml file with any of the variables you need overridden (my variable names/values might need some checking though). Brian On Friday, January 10, 2014 5:59:53 PM UTC-6, Adam Morris wrote: I have been building up a bunch of tasks for some standard configuration items. I have the basic tasks all working perfectly for new installs for both AIX and RedHat/CentOs 6. Now I'm testing against one of the older RedHat installs that we have (RedHat 5) and having to make some changes... So far things have been going well until I got to configuring syslog. On RedHat 6 I have to modify /etc/rsyslog.conf and restart rsylogd. On AIX it is slightly different so I set variables in my current OS specific group_vars files RedHat and AIX... On RedHat 5 most of the variables work perfectly for me, except /etc/rsyslog.conf becomes /etc/syslog.conf and rsyslogd becomes syslogd. So I can easily modify the variables I'm using to take that into account. But this means I need to set different variables for RedHat 5 and RedHat 6. although most of the variables are the same. So how would you suggest setting variables in this case? I can split tasks out so I don't need to set variables, but then I have much larger task files that contain essentially the same steps. I'm trying to reuse as much as possible, but I'm at a bit of a loss here. I was wondering if I could include a RedHat variable file into a RedHat5 or RedHat6 variable file but I can't see how to do it. I could keep the tasks the same and have almost identical variable files with minor changes for RedHat 5 and RedHat 6, but that is still not as clean as I would like. Any thoughts. Adam -- 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. For more options, visit https://groups.google.com/groups/opt_out.
[ansible-project] Re: How would you set variables in this case?
Would the following work? For the few variables that differ, substitute them at the beginning of the playbook. It could even allow you to use a single variable file if you extrapolate all your variables in this manner. vars: syslog_var: {{ ansible_lsb.id }}_{{ ansible_lsb.major_release ))_syslog_var syslog_var2: {{ ansible_lsb.id }}_{{ ansible_lsb.major_release ))_syslog_var2 and use {{ syslog_var }} in the tasks/templates. Then in your RHEL vars file: RedHat_5_syslog_var: foo RedHat_6_syslog_var: bar RedHat_5_syslog_var2: foo2 RedHat_6_syslog_var2: bar2 And similar for the AIX vars file. You could use conditionals at the task level, or in templates, but if you only have a couple differences, I think this is a simpler method. Lots of ways to accomplish this, depends on your wants and needs. My biggest concern is having others use/maintain the playbooks and being able to understand what's going on, and without having to grok the more difficult concepts. Ansible is pretty simple, but having a junior level sysadmin try to do things like address complex data or understanding variable precedence are items I'd like to avoid. Brian On Friday, January 10, 2014 7:19:12 PM UTC-6, Adam Morris wrote: On Friday, January 10, 2014 4:16:47 PM UTC-8, Brian Green wrote: How about keep your default variables in roles/vars/main.yml and then for variables that would be considered special case or overrides you put them elsewhere with higher precedence. For your RHEL 5 example, take a look at http://docs.ansible.com/playbooks_variables.html#conditional-imports and you could use something similar like vars/{{ ansible_lsb.id }}_{{ ansible_lsb.major_release }}.yml where you'd populate the RedHat_5.yml file with any of the variables you need overridden (my variable names/values might need some checking though). Brian I guess I wasn't as clear as I could have been... I currently have a single task that updates the syslog configuration file and restarts the syslog daemon. It works perfectly for AIX, RedHat 5 and RedHat 6. This is one of many tasks I have written so far. The problem I have is that for most of my tasks I have differences between RedHat and AIX that require variables... So I had two variables files that I am picking up, one for AIX and one for RedHat. This is the one place that RedHat 5 and RedHat 6 differ in a way that can easily be fixed with variables (rsylog versus syslog)... But I either copy my RedHat variable file and create two almost identical files with a difference of two lines out of 11, or I find another way of doing this... For the moment I've copied the RedHat file into RedHat5 and RedHat6. I was just wondering if there was a better way than treating RedHat 5 and RedHat 6 as different operating systems. Adam -- 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. For more options, visit https://groups.google.com/groups/opt_out.
[ansible-project] Re: How to skip Role Dependencies?
Have you tried something like: --- dependencies: - { role: some_role, when: some_role_dependency is not defined } ansible-playbook -i hosts some_role.yml -e some_role_dependency=false - skips dependency ansible-playbook -i hosts some_role.yml - executes dependency On Sunday, December 8, 2013 3:34:19 AM UTC-6, howa...@gmail.com wrote: Sometimes, we would like deploy a machine without the need for checking the Role Dependencies, because it is very slow for our playbook (up to 5 mins), is it possible? 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. For more options, visit https://groups.google.com/groups/opt_out.