James A. Peltier
2011-Oct-12 20:15 UTC
[Puppet Users] Setting savedefult options with augeas/puppet
Hi All, I''m trying to create a puppet manifest that sets the grub default= value to saved and the Windows option to savedefault for a dual_boot class. Setting the default= option is actually fairly easy, but I''m not sure how to create the savedefault entry for the Windows side. Anyone have to deal with this and have a suggestion? -- James A. Peltier IT Services - Research Computing Group Simon Fraser University - Burnaby Campus Phone : 778-782-6573 Fax : 778-782-3045 E-Mail : jpeltier@sfu.ca Website : http://www.sfu.ca/itservices http://blogs.sfu.ca/people/jpeltier I will do the best I can with the talent I have -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Luke Bigum
2011-Oct-13 08:24 UTC
[Puppet Users] Re: Setting savedefult options with augeas/puppet
Can you give me an example of a grub.conf file that you want to achieve? I don''t have a dual boot windows system so not exactly sure what option you mean. On Oct 12, 9:15 pm, "James A. Peltier" <jpelt...@sfu.ca> wrote:> Hi All, > > I''m trying to create a puppet manifest that sets the grub default= value to saved and the Windows option to savedefault for a dual_boot class. Setting the default= option is actually fairly easy, but I''m not sure how to create the savedefault entry for the Windows side. Anyone have to deal with this and have a suggestion? > > -- > James A. Peltier > IT Services - Research Computing Group > Simon Fraser University - Burnaby Campus > Phone : 778-782-6573 > Fax : 778-782-3045 > E-Mail : jpelt...@sfu.ca > Website :http://www.sfu.ca/itservices > http://blogs.sfu.ca/people/jpeltier > I will do the best I can with the talent I have-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
James Peltier
2011-Oct-13 22:16 UTC
Re: [Puppet Users] Re: Setting savedefult options with augeas/puppet
On Thu, Oct 13, 2011 at 1:24 AM, Luke Bigum <Luke.Bigum@lmax.com> wrote:> Can you give me an example of a grub.conf file that you want to > achieve? I don''t have a dual boot windows system so not exactly sure > what option you mean.> # grub.conf generated by anaconda > # > # Note that you do not have to rerun grub after making changes to this file > # NOTICE: You have a /boot partition. This means that > # all kernel and initrd paths are relative to /boot/, eg. > # root (hd0,2) > # kernel /vmlinuz-version ro root=/dev/ROOTDISK/root > # initrd /initrd-version.img > #boot=/dev/sda > default=0 > timeout=15 > splashimage=(hd0,2)/grub/splash.xpm.gz > hiddenmenu > password --md5 $1$CgIXv$laSfgcbmFW62.Y7PWbtBB0 > title CentOS (2.6.18-274.3.1.el5) > root (hd0,2) > kernel /vmlinuz-2.6.18-274.3.1.el5 ro root=/dev/ROOTDISK/root rhgb > quiet > initrd /initrd-2.6.18-274.3.1.el5.img > title Windows > rootnoverify (hd0,0) > chainloader +1 > >default= should be set to saved davedefault should be appended after chainloader +1 -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
James A. Peltier
2011-Oct-13 22:17 UTC
Re: [Puppet Users] Re: Setting savedefult options with augeas/puppet
----- Original Message ----- | On Thu, Oct 13, 2011 at 1:24 AM, Luke Bigum <Luke.Bigum@lmax.com> | wrote: | | > Can you give me an example of a grub.conf file that you want to | > achieve? I don''t have a dual boot windows system so not exactly sure | > what option you mean. | | | | | > # grub.conf generated by anaconda | > # | > # Note that you do not have to rerun grub after making changes to | > this file | > # NOTICE: You have a /boot partition. This means that | > # all kernel and initrd paths are relative to /boot/, eg. | > # root (hd0,2) | > # kernel /vmlinuz-version ro root=/dev/ROOTDISK/root | > # initrd /initrd-version.img | > #boot=/dev/sda | > default=0 | > timeout=15 | > splashimage=(hd0,2)/grub/splash.xpm.gz | > hiddenmenu | > password --md5 $1$CgIXv$laSfgcbmFW62.Y7PWbtBB0 | > title CentOS (2.6.18-274.3.1.el5) | > root (hd0,2) | > kernel /vmlinuz-2.6.18-274.3.1.el5 ro | > root=/dev/ROOTDISK/root rhgb | > quiet | > initrd /initrd-2.6.18-274.3.1.el5.img | > title Windows | > rootnoverify (hd0,0) | > chainloader +1 | > | > | | default= should be set to saved | davedefault should be appended after chainloader +1 savedefault should be appended after chainloader +1 -- James A. Peltier IT Services - Research Computing Group Simon Fraser University - Burnaby Campus Phone : 778-782-6573 Fax : 778-782-3045 E-Mail : jpeltier@sfu.ca Website : http://www.sfu.ca/itservices http://blogs.sfu.ca/people/jpeltier I will do the best I can with the talent I have -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Luke Bigum
2011-Oct-14 09:11 UTC
[Puppet Users] Re: Setting savedefult options with augeas/puppet
Cheers, I''ll walk you through how I came up with the augeas commands. Opening augtool and printing /files/boot/grup/menu.lst shows how the lense has constructed the augeas tree (edited for brevity): augtool> print /files/boot/grub/menu.lst/ /files/boot/grub/menu.lst /files/boot/grub/menu.lst/#comment[1] = "grub.conf generated by anaconda" ... /files/boot/grub/menu.lst/default = "0" /files/boot/grub/menu.lst/timeout = "0" /files/boot/grub/menu.lst/splashimage = "(hd0,0)/grub/splash.xpm.gz" ... /files/boot/grub/menu.lst/title[2] = "Fedora (2.6.40.4-5.fc15.x86_64)" /files/boot/grub/menu.lst/title[2]/root = "(hd0,0)" /files/boot/grub/menu.lst/title[2]/kernel = "/ vmlinuz-2.6.40.4-5.fc15.x86_64" /files/boot/grub/menu.lst/title[2]/kernel/ro ... /files/boot/grub/menu.lst/title[4] = "Windows" /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" /files/boot/grub/menu.lst/title[4]/chainloader = "+1" Looks like each boot option is created as in array format in the title branch of the tree, with a value of the actual title of the boot option. That makes finding just the Windows one very easy, however it depends on you knowing the title of the kernel option, which I''m going to assume you do. augtool> print /files/boot/grub/menu.lst/title[.="Windows"] /files/boot/grub/menu.lst/title[4] = "Windows" /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" /files/boot/grub/menu.lst/title[4]/chainloader = "+1" The period in the path expression /files/boot/grub/menu.lst/ title[.="Windows"] is a shortcut for self::*, which is tree node ''title'' in this case, so in laymans terms "print title where title Windows". As a learning exercise lets assume we don''t know the title of the Windows Grub option, but we assume that anything that has "chainloader+1" we need to do something with, we can use this path expression, which says "child tree nodes of the name ''chainloader'' with the value ''+1''". augtool> print /files/boot/grub/menu.lst/ title[child::chainloader="+1"] /files/boot/grub/menu.lst/title[4] = "Windows" /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" /files/boot/grub/menu.lst/title[4]/chainloader = "+1" It can be simplified by dropping the "child::" bit, which is an augeas shortcut: augtool> print /files/boot/grub/menu.lst/title[chainloader="+1"] /files/boot/grub/menu.lst/title[4] = "Windows" /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" /files/boot/grub/menu.lst/title[4]/chainloader = "+1" Back to your example, adding the savedefault node: augtool> ins savedefault after /files/boot/grub/menu.lst/ title[.="Windows"]/chainloader augtool> print /files/boot/grub/menu.lst/title[.="Windows"] /files/boot/grub/menu.lst/title[4] = "Windows" /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" /files/boot/grub/menu.lst/title[4]/chainloader = "+1" /files/boot/grub/menu.lst/title[4]/savedefault augtool> save Saved 1 file(s) augootl> quit [root@biguml-laptop ~]# tail -n 4 /boot/grub/grub.conf title Windows rootnoverify (hd0,0) chainloader +1 savedefault Looks good. You piqued my interest with the savedefault option though so I looked it up. Are you sure you don''t want it on every kernel boot option so if you change into different Linux kernels it remembers them as well? You can do that with augeas too, using a combination of setm and clearm (set multiple and clear multiple). First use setm to create the ''savedefault'' node as a child of all ''title'' nodes and then clear the value of these node, as the ''savedefault'' option doesn''t have a value: augtool> setm /files/boot/grub/menu.lst/title savedefault 1 augtool> clearm /files/boot/grub/menu.lst/title savedefault augtool> save Saved 1 file(s) [root@biguml-laptop ~]# cat /boot/grub/grub.conf # grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/mapper/vg_root-lv_root # initrd /initrd-[generic-]version.img #boot=/dev/sda default=0 timeout=0 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title Fedora (2.6.40.6-0.fc15.x86_64) root (hd0,0) kernel /vmlinuz-2.6.40.6-0.fc15.x86_64 ro root=/dev/mapper/vg_root- lv_root rd_LUKS_UUID=luks-08041027-ab79-4f45-87b0-756d1eeb26e5 rd_LVM_LV=vg_root/lv_root rd_NO_MD rd_NO_DM LANG=en_GB.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=uk rhgb quiet initrd /initramfs-2.6.40.6-0.fc15.x86_64.img savedefault title Windows rootnoverify (hd0,0) chainloader +1 savedefault There we go. You might run into a problem using setm in Puppet, probably clearm as well, as I don''t think ruby-augeas supports it properly (I can''t remember the error). In my manifests I call augtool in an Exec resource. In Fedora at least, augtool -s "<command>" wasn''t saving the files either so I had to get even more hacky and use a temporary file (urgh...). This is from one of my modules: $aug_tmp_file = "/tmp/.puppet_base_augeas_cmd_file" exec { "set elevator=deadline in $grub_menu": command => "echo ''setm /files${grub_menu}/title kernel/elevator deadline'' > ${aug_tmp_file} && /usr/bin/augtool -s -f ${aug_tmp_file} && rm -f ${aug_tmp_file}", onlyif => "grep ''kernel /vmlinuz-2'' ${grub_menu} | grep -v elevator=deadline", require => Package["augeas"], } Hope that helps, -Luke On Oct 13, 11:17 pm, "James A. Peltier" <jpelt...@sfu.ca> wrote:> ----- Original Message ----- > | On Thu, Oct 13, 2011 at 1:24 AM, Luke Bigum <Luke.Bi...@lmax.com> > | wrote: > | > | > Can you give me an example of a grub.conf file that you want to > | > achieve? I don''t have a dual boot windows system so not exactly sure > | > what option you mean. > | > | > | > | > | > # grub.conf generated by anaconda > | > # > | > # Note that you do not have to rerun grub after making changes to > | > this file > | > # NOTICE: You have a /boot partition. This means that > | > # all kernel and initrd paths are relative to /boot/, eg. > | > # root (hd0,2) > | > # kernel /vmlinuz-version ro root=/dev/ROOTDISK/root > | > # initrd /initrd-version.img > | > #boot=/dev/sda > | > default=0 > | > timeout=15 > | > splashimage=(hd0,2)/grub/splash.xpm.gz > | > hiddenmenu > | > password --md5 $1$CgIXv$laSfgcbmFW62.Y7PWbtBB0 > | > title CentOS (2.6.18-274.3.1.el5) > | > root (hd0,2) > | > kernel /vmlinuz-2.6.18-274.3.1.el5 ro > | > root=/dev/ROOTDISK/root rhgb > | > quiet > | > initrd /initrd-2.6.18-274.3.1.el5.img > | > title Windows > | > rootnoverify (hd0,0) > | > chainloader +1 > | > > | > > | > | default= should be set to saved > | davedefault should be appended after chainloader +1 > > savedefault should be appended after chainloader +1 > > -- > James A. Peltier > IT Services - Research Computing Group > Simon Fraser University - Burnaby Campus > Phone : 778-782-6573 > Fax : 778-782-3045 > E-Mail : jpelt...@sfu.ca > Website :http://www.sfu.ca/itservices > http://blogs.sfu.ca/people/jpeltier > I will do the best I can with the talent I have-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
James A. Peltier
2011-Oct-16 23:58 UTC
Re: [Puppet Users] Re: Setting savedefult options with augeas/puppet
----- Original Message ----- | Cheers, I''ll walk you through how I came up with the augeas commands. | | Opening augtool and printing /files/boot/grup/menu.lst shows how the | lense has constructed the augeas tree (edited for brevity): | | augtool> print /files/boot/grub/menu.lst/ | /files/boot/grub/menu.lst | /files/boot/grub/menu.lst/#comment[1] = "grub.conf generated by | anaconda" | ... | /files/boot/grub/menu.lst/default = "0" | /files/boot/grub/menu.lst/timeout = "0" | /files/boot/grub/menu.lst/splashimage = "(hd0,0)/grub/splash.xpm.gz" | ... | /files/boot/grub/menu.lst/title[2] = "Fedora (2.6.40.4-5.fc15.x86_64)" | /files/boot/grub/menu.lst/title[2]/root = "(hd0,0)" | /files/boot/grub/menu.lst/title[2]/kernel = "/ | vmlinuz-2.6.40.4-5.fc15.x86_64" | /files/boot/grub/menu.lst/title[2]/kernel/ro | ... | /files/boot/grub/menu.lst/title[4] = "Windows" | /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" | /files/boot/grub/menu.lst/title[4]/chainloader = "+1" | | Looks like each boot option is created as in array format in the title | branch of the tree, with a value of the actual title of the boot | option. That makes finding just the Windows one very easy, however it | depends on you knowing the title of the kernel option, which I''m going | to assume you do. | | augtool> print /files/boot/grub/menu.lst/title[.="Windows"] | /files/boot/grub/menu.lst/title[4] = "Windows" | /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" | /files/boot/grub/menu.lst/title[4]/chainloader = "+1" | | The period in the path expression /files/boot/grub/menu.lst/ | title[.="Windows"] is a shortcut for self::*, which is tree node | ''title'' in this case, so in laymans terms "print title where title | Windows". | | As a learning exercise lets assume we don''t know the title of the | Windows Grub option, but we assume that anything that has | "chainloader| +1" we need to do something with, we can use this path expression, | which says "child tree nodes of the name ''chainloader'' with the value | ''+1''". | | augtool> print /files/boot/grub/menu.lst/ | title[child::chainloader="+1"] | /files/boot/grub/menu.lst/title[4] = "Windows" | /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" | /files/boot/grub/menu.lst/title[4]/chainloader = "+1" | | It can be simplified by dropping the "child::" bit, which is an augeas | shortcut: | | augtool> print /files/boot/grub/menu.lst/title[chainloader="+1"] | /files/boot/grub/menu.lst/title[4] = "Windows" | /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" | /files/boot/grub/menu.lst/title[4]/chainloader = "+1" | | Back to your example, adding the savedefault node: | | augtool> ins savedefault after /files/boot/grub/menu.lst/ | title[.="Windows"]/chainloader | augtool> print /files/boot/grub/menu.lst/title[.="Windows"] | /files/boot/grub/menu.lst/title[4] = "Windows" | /files/boot/grub/menu.lst/title[4]/rootnoverify = "(hd0,0)" | /files/boot/grub/menu.lst/title[4]/chainloader = "+1" | /files/boot/grub/menu.lst/title[4]/savedefault | augtool> save | Saved 1 file(s) | augootl> quit | [root@biguml-laptop ~]# tail -n 4 /boot/grub/grub.conf | title Windows | rootnoverify (hd0,0) | chainloader +1 | savedefault | | Looks good. | | You piqued my interest with the savedefault option though so I looked | it up. Are you sure you don''t want it on every kernel boot option so | if you change into different Linux kernels it remembers them as well? | | You can do that with augeas too, using a combination of setm and | clearm (set multiple and clear multiple). | | First use setm to create the ''savedefault'' node as a child of all | ''title'' nodes and then clear the value of these node, as the | ''savedefault'' option doesn''t have a value: | | augtool> setm /files/boot/grub/menu.lst/title savedefault 1 | augtool> clearm /files/boot/grub/menu.lst/title savedefault | augtool> save | Saved 1 file(s) | | [root@biguml-laptop ~]# cat /boot/grub/grub.conf | # grub.conf generated by anaconda | # | # Note that you do not have to rerun grub after making changes to this | file | # NOTICE: You have a /boot partition. This means that | # all kernel and initrd paths are relative to /boot/, eg. | # root (hd0,0) | # kernel /vmlinuz-version ro root=/dev/mapper/vg_root-lv_root | # initrd /initrd-[generic-]version.img | #boot=/dev/sda | default=0 | timeout=0 | splashimage=(hd0,0)/grub/splash.xpm.gz | hiddenmenu | title Fedora (2.6.40.6-0.fc15.x86_64) | root (hd0,0) | kernel /vmlinuz-2.6.40.6-0.fc15.x86_64 ro root=/dev/mapper/vg_root- | lv_root rd_LUKS_UUID=luks-08041027-ab79-4f45-87b0-756d1eeb26e5 | rd_LVM_LV=vg_root/lv_root rd_NO_MD rd_NO_DM LANG=en_GB.UTF-8 | SYSFONT=latarcyrheb-sun16 KEYTABLE=uk rhgb quiet | initrd /initramfs-2.6.40.6-0.fc15.x86_64.img | savedefault | title Windows | rootnoverify (hd0,0) | chainloader +1 | savedefault | | | There we go. | | You might run into a problem using setm in Puppet, probably clearm as | well, as I don''t think ruby-augeas supports it properly (I can''t | remember the error). In my manifests I call augtool in an Exec | resource. In Fedora at least, augtool -s "<command>" wasn''t saving the | files either so I had to get even more hacky and use a temporary file | (urgh...). This is from one of my modules: | | $aug_tmp_file = "/tmp/.puppet_base_augeas_cmd_file" | exec { "set elevator=deadline in $grub_menu": | command => "echo ''setm /files${grub_menu}/title kernel/elevator | deadline'' > ${aug_tmp_file} && /usr/bin/augtool -s -f ${aug_tmp_file} | && rm -f ${aug_tmp_file}", | onlyif => "grep ''kernel /vmlinuz-2'' ${grub_menu} | grep -v | elevator=deadline", | require => Package["augeas"], | } | | Hope that helps, | | -Luke | Thanks for the detailed reply Luke. I''ve come up with the following class and it works, however, keeps adding savedefault to the end so I''m going to have to add an onlyif statement to stop that from happening. I''m still trying to work out that onlyif statement right now, but this was incredibly helpful. class windows_default_boot { augeas{ "set_windows_to_default" : context => "/files/etc/grub.conf", changes => [ "ins savedefault after /files/etc/grub.conf/title[.=''Windows'']/chainloader", ], } } -- James A. Peltier IT Services - Research Computing Group Simon Fraser University - Burnaby Campus Phone : 778-782-6573 Fax : 778-782-3045 E-Mail : jpeltier@sfu.ca Website : http://www.sfu.ca/itservices http://blogs.sfu.ca/people/jpeltier I will do the best I can with the talent I have -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
James A. Peltier
2011-Oct-17 00:01 UTC
Re: [Puppet Users] Re: Setting savedefult options with augeas/puppet
----- Original Message ----- | | You piqued my interest with the savedefault option though so I | | looked | | it up. Are you sure you don''t want it on every kernel boot option so | | if you change into different Linux kernels it remembers them as | | well? BTW: No, this is not what this is intended to do. This is intended to allow us to define which machines should boot Windows by default only. Setting the savedefault parameter on all would not perform the steps we want. -- James A. Peltier IT Services - Research Computing Group Simon Fraser University - Burnaby Campus Phone : 778-782-6573 Fax : 778-782-3045 E-Mail : jpeltier@sfu.ca Website : http://www.sfu.ca/itservices http://blogs.sfu.ca/people/jpeltier I will do the best I can with the talent I have -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
James A. Peltier
2011-Oct-17 00:59 UTC
Re: [Puppet Users] Re: Setting savedefult options with augeas/puppet (SOLVED)
The following class seems to do exactly what I needed it to do. It sets the default context to saved and creates a savedefault parameter for the Windows entry that exists. This method also does not require a onlyif if statement which is much better than the ins after option that was proposed by Luke although his detailed explaination is still very much welcomed. I just did it a different way. ;) class windows_default_boot { augeas{ "set_windows_to_default" : context => "/files/etc/grub.conf", changes => [ "set /files/etc/grub.conf/default saved", "set /files/etc/grub.conf/title[.=''Windows'']/savedefault 0", "clear /files/etc/grub.conf/title[.=''Windows'']/savedefault", ], } } Thanks again! -- James A. Peltier IT Services - Research Computing Group Simon Fraser University - Burnaby Campus Phone : 778-782-6573 Fax : 778-782-3045 E-Mail : jpeltier@sfu.ca Website : http://www.sfu.ca/itservices http://blogs.sfu.ca/people/jpeltier I will do the best I can with the talent I have -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.