automateit 0.70923

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data.tar.gz.sig +1 -0
  2. data/CHANGES.txt +100 -0
  3. data/Hoe.rake +35 -0
  4. data/Manifest.txt +111 -0
  5. data/README.txt +44 -0
  6. data/Rakefile +284 -0
  7. data/TESTING.txt +57 -0
  8. data/TODO.txt +26 -0
  9. data/TUTORIAL.txt +390 -0
  10. data/bin/ai +3 -0
  11. data/bin/aifield +82 -0
  12. data/bin/aitag +128 -0
  13. data/bin/automateit +117 -0
  14. data/docs/friendly_errors.txt +50 -0
  15. data/docs/previews.txt +86 -0
  16. data/env.sh +4 -0
  17. data/examples/basic/Rakefile +26 -0
  18. data/examples/basic/config/automateit_env.rb +16 -0
  19. data/examples/basic/config/fields.yml +3 -0
  20. data/examples/basic/config/tags.yml +13 -0
  21. data/examples/basic/dist/README.txt +9 -0
  22. data/examples/basic/dist/myapp_server.erb +30 -0
  23. data/examples/basic/install.log +15 -0
  24. data/examples/basic/lib/README.txt +10 -0
  25. data/examples/basic/recipes/README.txt +4 -0
  26. data/examples/basic/recipes/install.rb +53 -0
  27. data/examples/basic/recipes/uninstall.rb +6 -0
  28. data/gpl.txt +674 -0
  29. data/lib/automateit.rb +66 -0
  30. data/lib/automateit/account_manager.rb +106 -0
  31. data/lib/automateit/account_manager/linux.rb +171 -0
  32. data/lib/automateit/account_manager/passwd.rb +69 -0
  33. data/lib/automateit/account_manager/portable.rb +136 -0
  34. data/lib/automateit/address_manager.rb +165 -0
  35. data/lib/automateit/address_manager/linux.rb +80 -0
  36. data/lib/automateit/address_manager/portable.rb +37 -0
  37. data/lib/automateit/cli.rb +80 -0
  38. data/lib/automateit/common.rb +65 -0
  39. data/lib/automateit/constants.rb +33 -0
  40. data/lib/automateit/edit_manager.rb +292 -0
  41. data/lib/automateit/error.rb +10 -0
  42. data/lib/automateit/field_manager.rb +103 -0
  43. data/lib/automateit/interpreter.rb +641 -0
  44. data/lib/automateit/package_manager.rb +242 -0
  45. data/lib/automateit/package_manager/apt.rb +63 -0
  46. data/lib/automateit/package_manager/egg.rb +64 -0
  47. data/lib/automateit/package_manager/gem.rb +179 -0
  48. data/lib/automateit/package_manager/portage.rb +69 -0
  49. data/lib/automateit/package_manager/yum.rb +65 -0
  50. data/lib/automateit/platform_manager.rb +47 -0
  51. data/lib/automateit/platform_manager/darwin.rb +30 -0
  52. data/lib/automateit/platform_manager/debian.rb +26 -0
  53. data/lib/automateit/platform_manager/freebsd.rb +25 -0
  54. data/lib/automateit/platform_manager/gentoo.rb +26 -0
  55. data/lib/automateit/platform_manager/lsb.rb +40 -0
  56. data/lib/automateit/platform_manager/struct.rb +78 -0
  57. data/lib/automateit/platform_manager/uname.rb +29 -0
  58. data/lib/automateit/platform_manager/windows.rb +33 -0
  59. data/lib/automateit/plugin.rb +7 -0
  60. data/lib/automateit/plugin/base.rb +32 -0
  61. data/lib/automateit/plugin/driver.rb +218 -0
  62. data/lib/automateit/plugin/manager.rb +232 -0
  63. data/lib/automateit/project.rb +460 -0
  64. data/lib/automateit/root.rb +14 -0
  65. data/lib/automateit/service_manager.rb +79 -0
  66. data/lib/automateit/service_manager/chkconfig.rb +39 -0
  67. data/lib/automateit/service_manager/rc_update.rb +37 -0
  68. data/lib/automateit/service_manager/sysv.rb +126 -0
  69. data/lib/automateit/service_manager/update_rcd.rb +35 -0
  70. data/lib/automateit/shell_manager.rb +261 -0
  71. data/lib/automateit/shell_manager/base_link.rb +67 -0
  72. data/lib/automateit/shell_manager/link.rb +24 -0
  73. data/lib/automateit/shell_manager/portable.rb +421 -0
  74. data/lib/automateit/shell_manager/symlink.rb +32 -0
  75. data/lib/automateit/shell_manager/which.rb +25 -0
  76. data/lib/automateit/tag_manager.rb +63 -0
  77. data/lib/automateit/tag_manager/struct.rb +101 -0
  78. data/lib/automateit/tag_manager/tag_parser.rb +91 -0
  79. data/lib/automateit/tag_manager/yaml.rb +29 -0
  80. data/lib/automateit/template_manager.rb +55 -0
  81. data/lib/automateit/template_manager/base.rb +172 -0
  82. data/lib/automateit/template_manager/erb.rb +17 -0
  83. data/lib/ext/metaclass.rb +17 -0
  84. data/lib/ext/object.rb +18 -0
  85. data/lib/hashcache.rb +22 -0
  86. data/lib/helpful_erb.rb +63 -0
  87. data/lib/nested_error.rb +33 -0
  88. data/lib/queued_logger.rb +68 -0
  89. data/lib/tempster.rb +239 -0
  90. data/misc/index_gem_repository.rb +303 -0
  91. data/misc/setup_egg.rb +12 -0
  92. data/misc/setup_gem_dependencies.sh +7 -0
  93. data/misc/setup_rubygems.sh +21 -0
  94. data/misc/which.cmd +6 -0
  95. data/spec/extras/automateit_service_sysv_test +50 -0
  96. data/spec/extras/scratch.rb +15 -0
  97. data/spec/extras/simple_recipe.rb +8 -0
  98. data/spec/integration/account_manager_spec.rb +218 -0
  99. data/spec/integration/address_manager_linux_spec.rb +119 -0
  100. data/spec/integration/address_manager_portable_spec.rb +30 -0
  101. data/spec/integration/cli_spec.rb +215 -0
  102. data/spec/integration/examples_spec.rb +54 -0
  103. data/spec/integration/examples_spec_editor.rb +71 -0
  104. data/spec/integration/package_manager_spec.rb +104 -0
  105. data/spec/integration/platform_manager_spec.rb +69 -0
  106. data/spec/integration/service_manager_sysv_spec.rb +115 -0
  107. data/spec/integration/shell_manager_spec.rb +471 -0
  108. data/spec/integration/template_manager_erb_spec.rb +31 -0
  109. data/spec/spec_helper.rb +23 -0
  110. data/spec/unit/edit_manager_spec.rb +162 -0
  111. data/spec/unit/field_manager_spec.rb +79 -0
  112. data/spec/unit/hashcache_spec.rb +28 -0
  113. data/spec/unit/interpreter_spec.rb +98 -0
  114. data/spec/unit/platform_manager_spec.rb +44 -0
  115. data/spec/unit/plugins_spec.rb +253 -0
  116. data/spec/unit/tag_manager_spec.rb +189 -0
  117. data/spec/unit/template_manager_erb_spec.rb +137 -0
  118. metadata +249 -0
  119. metadata.gz.sig +0 -0
@@ -0,0 +1,57 @@
1
+ == AutomateIt's self-test
2
+
3
+ AutomateIt ensures that it works correctly, and stays working, by using a rigorous self-test suite. This suite is written using the RSpec tool and its files are stored in the software installation's +spec+ directory. You must install the +rake+ and +rspec+ Gems to run the tests.
4
+
5
+ === Types of tests
6
+
7
+ <b>Unit tests</b> are quick and safe because they don't write to the disk or alter your system.
8
+
9
+ For example, <tt>spec/unit/template_manager_erb_spec.rb</tt> exercises AutomateIt::TemplateManager::ERB by rendering templates to memory. Because it doesn't write to the disk, you can safely run it without worrying about it damaging your system.
10
+
11
+ <b>Integration tests</b> are slow and potentially dangerous because they write to disk and alter your system. Great care is taken to make sure these don't cause damage, but because they modify the system, there is a potential risk. These tests are designed to fail before doing anything if they detect that they might cause damage. The tests will clean up after themselves when done to remove any changes made to the system. To put "dangerous" in context, these tests are run before every release, so the likelihood of actual damage is very low.
12
+
13
+ For example, the <tt>spec/integration/account_manager_spec.rb</tt> exercises the AutomateIt::AccountManager by adding and deleting users and groups. To make sure it doesn't cause harm, it uses dummy users with names like +automateit_testuser+. Before it starts the test, it will check for these users and fail the entire test if they're present. This ensures that it won't destroy an existing account in the unlikely event that you have a user with such a name.
14
+
15
+ === Understanding warnings
16
+
17
+ When the tests can't check something, they'll print warning messages. These warnings are normal and expected. They are *not* errors and do not imply that something is broken.
18
+
19
+ For example, if you run the integration test suite as a non-root user, it will warn you that it can't test some commands because you don't have the necessary privileges:
20
+
21
+ NOTE: Must be root to check 'chown' in ./spec/integration/shell_manager_spec.rb
22
+
23
+ You will also get warnings about drivers that are not available on your platform. For example, Ubuntu systems don't include the YUM package manager, so there's no way to test it on an Ubuntu system. So if you run the integration tests on an Ubuntu system, you'll get a warning like:
24
+
25
+ NOTE: Can't check AutomateIt::PackageManager::YUM on this platform, ./spec/integration/package_manager_spec.rb
26
+
27
+ === Running an individual test
28
+
29
+ Run an individual test, like <tt>spec/unit/template_manager_erb_spec.rb</tt>, by executing the Unix shell command:
30
+
31
+ spec spec/unit/template_manager_erb_spec.rb
32
+
33
+ === Running test suites
34
+
35
+ To run the +unit+ test suite, execute the following command from the Unix shell:
36
+
37
+ rake spec
38
+
39
+ To run all the test suites, including +unit+ and +integration+, execute the following command from the Unix shell:
40
+
41
+ rake spec:all
42
+
43
+ The integration test can take a few minutes and will pause for long periods of time while appearing to do nothing. This is normal, expected and there's nothing that can be done to "fix" this. For example, when testing the PackageManager::Gem driver, the test must wait for the +gem+ program to download fresh package indexes and this can take a long time.
44
+
45
+ === Code coverage reports
46
+
47
+ You can generate a code coverage report for the +unit+ test suite by running:
48
+
49
+ rake rcov
50
+
51
+ Or a report for all the suites, including +unit+ and +integration+, by running:
52
+
53
+ rake rcov:all
54
+
55
+ These tasks will create a +coverage+ directory with the report files.
56
+
57
+ Note that because no single platform can run all the code, you'll never be able to get 100% coverage.
@@ -0,0 +1,26 @@
1
+ KEY: Important? Urgent? Easy? 1=yes, 0=no
2
+
3
+ #===[ App ]=============================================================
4
+
5
+ 101 Download -- Add OpenURI wrapper from gTag
6
+ 100 Shell -- Expand glob patterns, e.g. chown_R(500, 500, "*")
7
+
8
+ 101 CLI -- Add tags via command-line
9
+ 100 Edit -- Display summary of edits, return with :details as [rv, list]
10
+ 100 Shell -- Incorporate which.cmd so #which can work on Windows
11
+ 100 Interpreter#invoke and HelpfulERB -- Extract error context code into class
12
+
13
+ 000 Shell#chperm -- With symbolic mode, wrap `chmod -v` as temporary workaround?
14
+ 000 Changes -- Write parser and new format so I can use "#" symbol
15
+ 000 FreeBSD -- Write driver for PackageManager::Ports
16
+ 000 Darwin -- Write drivers, e.g. PackageManager for Fink, MacPorts, Pkgsrc
17
+
18
+ ??? Shell -- Return false or list, never single item?
19
+ ??? Shell -- Extract FileManager? change docs
20
+ ??? Driver -- How to determine if a manager or driver method is available? Manager#available?, Manager#available and Driver#suitable? only say if it should be a default.
21
+
22
+ #===[ Web ]=============================================================
23
+ 100 Index: Call for pilot users, driver authors
24
+ 000 CSS: Highlight active menu by setting a class, e.g., current_about.
25
+ 000 Kattare is redirecting to www, why?
26
+ 000 Add error page
@@ -0,0 +1,390 @@
1
+ == A hands-on tutorial for learning AutomateIt
2
+
3
+ <em>AutomateIt is an open-source tool for automating the setup and maintenance of servers.</em>
4
+
5
+ This hands-on guide will teach you to use AutomateIt and explain where to find more detailed instructions.
6
+
7
+ It's recommended that you see the Screenshots[http://automateit.org/screenshots] of AutomateIt in action to get a quick idea of what AutomateIt is all about.
8
+
9
+ AutomateIt is feature-complete, exceeds the capabilities of similar products, and ensures its quality with a self-test suite. However, this is a young product and users are expected to be technically proficient, willing to accept rough spots, to work through problems and upgrade frequently.
10
+
11
+ Please sign up for RSS change notifications[http://automateit.org/changes] so you know when upgrades are available.
12
+
13
+ === Ruby
14
+
15
+ AutomateIt is written using the Ruby programming language. If you haven't used Ruby, you'll find it easy to learn and a pleasure to use. If you already know the basics of Perl, Python, PHP or Java, you'll be able to pick up Ruby almost instantly. Although AutomateIt provides much of the structure and commands needed, you still need to know the basic Ruby syntax to get by.
16
+
17
+ Some Ruby resources:
18
+ * Ruby's official documentation page: http://www.ruby-lang.org/en/documentation/
19
+ * The online "Ruby user's guide" is a gentle introduction to the Ruby language: http://www.ruby-doc.org/docs/UsersGuide/rg/
20
+ * The online "Ruby syntax" is a condensed, one-page reference of the language's syntax: http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html
21
+ * The online "Programming Ruby" site provides a fairly detailed walk-through of the language: http://www.ruby-doc.org/docs/ProgrammingRuby/
22
+ * The "Practical Ruby for System Administration" book is a gentle introduction for sysadmins, which may be much easier for them to understand than a book aimed at software engineers, and it covers many system administration automation topics that'll be of use for Automateit recipes: http://www.apress.com/book/view/1590598210
23
+ * The "Programming Ruby" book provides a much more complete language reference than any online reference: http://www.pragmaticprogrammer.com/titles/ruby/index.html
24
+
25
+ === Typographical conventions
26
+
27
+ AutomateIt's technical documentation uses the following typographical conventions:
28
+
29
+ * +automateit+ -- A file, command or variable.
30
+ * <tt>:verbosity</tt> -- A symbol, usually used in an options hash.
31
+ * AutomateIt::ShellManager -- A class, with a link to its documentation. You can also find a link to this class's documentation in the "Classes" pane on the left.
32
+ * AutomateIt::ShellManager#sh -- A method, with a link to its documentation. You can also find a link to this method's documentation in the "Methods" pane on the left.
33
+ * Ruby code:
34
+ puts "Ruby code"
35
+ * Unix shell command, although the prompt may be left off when obvious:
36
+ you@host:myproject> echo "Unix command run from the 'myproject' directory"
37
+ * AutomateIt interactive shell command, although the prompt may be left off when obvious:
38
+ ai> puts "I'm in the Interpreter"
39
+
40
+ === Glossary
41
+
42
+ AutomateIt uses a number of unique terms:
43
+
44
+ * *Recipe* -- A file that contains AutomateIt commands.
45
+ * *Project* -- A special directory that contains related recipes and helper files.
46
+ * *Interpreter* -- The part of AutomateIt that runs commands.
47
+ * *Plugin* -- A part of AutomateIt that describes related features.
48
+ * *Driver* -- An implementation of a plugin. There are often multiple drivers per plugin.
49
+
50
+ === Interactive shell
51
+
52
+ AutomateIt comes with an interactive shell, which is useful for exploring commands and developing recipes.
53
+
54
+ Here's what an interactive shell session looks like (text following the <tt>#</tt> symbol explains the line and is not actually part of the session):
55
+
56
+ you@host:tmp> automateit # Start the AutomateIt interactive shell
57
+ => AutomateIt Shell v0.5.0 # Welcome message from AutomateIt
58
+ ai> puts "Hello world!" # AutomateIt's prompt and a user command
59
+ Hello world! # Output from the "puts" command
60
+ => nil # Return value of the "puts" command
61
+ ai> self.class # Prompt and another user command
62
+ => AutomateIt::Interpreter # Return value of "self.class"
63
+ ai> <CTRL-D> # Press <CTRL-D> to exit the shell
64
+ you@host:tmp> # We're back to the Unix shell
65
+
66
+ === Recipe files
67
+
68
+ The Interpreter can run recipe files that contain AutomateIt commands.
69
+
70
+ For example, create a <tt>/tmp/hello.rb</tt> file that contains:
71
+
72
+ puts "Hello, I'm an #{self.class}"
73
+
74
+ Then run the recipe:
75
+
76
+ you@host:tmp> automateit /tmp/hello.rb
77
+ Hello, I'm an AutomateIt::Interpreter
78
+
79
+ === String evaluation
80
+
81
+ The Interpreter can also evaluate commands as strings:
82
+
83
+ you@host:tmp> automateit -e 'puts self.class'
84
+ AutomateIt::Interpreter
85
+
86
+ === Exploring the Interpreter's unique methods
87
+
88
+ The Interpreter provides some unique methods:
89
+
90
+ ai> unique_methods
91
+ => ["account_manager", "address_manager", "cd", "chmod", ...
92
+
93
+ The names are Interpreter methods. Names ending with +_manager+ are methods for accessing plugins, while the rest are normal methods. The AutomateIt::Interpreter documentation provides a list of these methods and links to their individual documentation.
94
+
95
+ For example, one of the commands listed is +pwd+, which can be used like this:
96
+
97
+ ai> pwd
98
+ => "/tmp"
99
+
100
+ AutomateIt provides many commands that work just like the Unix shell commands you already know, so you'll be productive quickly.
101
+
102
+ === Conditional execution
103
+
104
+ AutomateIt executes only the commands needed to achieve a desired state, which makes recipes repeatable, reusable and maintainable.
105
+
106
+ Eliminating the distinction between setup and maintenance means the same command can perform both tasks without concern for the host's condition. A properly-written recipe can be run and re-run immediately afterwards, and it will do nothing the second time because all changes have already been applied.
107
+
108
+ An example can make this clearer -- again the text following the <tt>#</tt> symbol explains the commands and is not part of the session:
109
+
110
+ you@host:tmp> automateit # Start the AutomateIt interactive shell
111
+ => AutomateIt Shell v0.5.0 # Welcome message
112
+ ai> mkdir "asdfasdf" # Create a directory called "asdfasdf"
113
+ ** mkdir asdfasdf # Message showing that directory was created
114
+ => ["asdfasdf"] # Return value with array of directories created
115
+ ai> mkdir "asdfasdf" # Try to create the same directory again
116
+ => false # Nothing happened, the directory already exists
117
+ ai> rmdir "asdfasdf" # Remove the directory
118
+ ** rmdir asdfasdf # Message showing that directory was removed
119
+ => ["asdfasdf"] # Return value with array of directories removed
120
+ ai> rmdir "asdfasdf" # Try to remove the directory again
121
+ => false # Nothing happened, there's no directory to remove
122
+
123
+ Notice how the second time +mkdir+ was run above, it returned +false+ and didn't create a directory? That's the conditional execution in action, realizing the action has already been performed. Similarly, the +rmdir+ only ran the first time, but returned +false+ and took no action when the directory was already gone. You can use the return values of these commands to write sophisticated logic of your own based on what actions took place.
124
+
125
+ === Plugins
126
+
127
+ AutomateIt uses an extensible plugin architecture to group together related commands:
128
+
129
+ * AutomateIt::AccountManager -- Manipulates users and groups.
130
+ * AutomateIt::AddressManager -- Manipulates host's network addresses.
131
+ * AutomateIt::EditManager -- Edits files and strings.
132
+ * AutomateIt::FieldManager -- Queries configuration variables.
133
+ * AutomateIt::PackageManager -- Manipulates software packages.
134
+ * AutomateIt::PlatformManager -- Queries platform, such as its OS version.
135
+ * AutomateIt::ServiceManager -- Manipulates services, such as Unix daemons.
136
+ * AutomateIt::ShellManager -- Manipulates files and executes Unix commands.
137
+ * AutomateIt::TagManager -- Groups hosts by role and queries membership.
138
+ * AutomateIt::TemplateManager -- Renders templates to files.
139
+
140
+ Plugins can be accessed from the Interpreter like this:
141
+
142
+ ai> shell_manager.pwd
143
+ => "/tmp"
144
+
145
+ The most common plugin methods have aliased shortcuts. For example, +pwd+ is the alias for <tt>shell_manager.pwd</tt>. These are documented in AutomateIt::Interpreter's "Aliased methods."
146
+
147
+ === Drivers
148
+
149
+ Each plugin has one or more drivers that implement its functionality.
150
+
151
+ For example:
152
+
153
+ * AutomateIt::ShellManager -- A plugin for running shell commands.
154
+ * AutomateIt::ShellManager::Portable -- A portable but limited-functionality driver that implements the ShellManager's methods.
155
+ * AutomateIt::ShellManager::Unix -- A full-featured driver implementing ShellManager's methods that only runs on Unix-like systems.
156
+
157
+ === Plugins provide APIs, drivers provide implementations
158
+
159
+ Plugins describe consistent interfaces for related features, and drivers implement this API for different tools.
160
+
161
+ For example, AutomateIt provides a common API for all packaging tools: AutomateIt::PackageManager. It provides drivers for packaging tools like APT, YUM, Gem, Egg and others. To install a package called +foo+ with the +apt+ driver:
162
+
163
+ ai> package_manager.install "foo", :with => :apt
164
+
165
+ AutomateIt will check if +foo+ is installed, install it if needed, or do nothing if the package is present. This API is the same for all packaging tools, making it easy to get work done by using high-level AutomateIt commands instead of cryptic tool-specific commands. Although AutomateIt uses the low-level tools, it uses them with best-practices approaches and hides the senseless complexity from the user.
166
+
167
+ What's the big deal? Consider how one would install packages from the Unix shell. Most packaging tools are pathologically dysfunctional and make it bafflingly difficult to programmatically install or uninstall packages, or tell if a package is installed. Many don't use exit values and require complex output parsing. Others require user-input even when it's obvious that none is needed. Almost all make it necessary to write conditional code because they'll either fail with errors if told to install an existing package, destroy an existing setup, or install duplicate packages. Writing Unix shell code to handle all these quirks is frustrating and risky.
168
+
169
+ Here's a sample Unix shell command for installing a package using one of the simplest, most reasonable tools available -- although note that unlike AutomateIt, this shell command can't handle multiple packages, is slower, can't be previewed, and has no consistent error handling:
170
+
171
+ if dpkg-query -W --showformat '${Status}\n' foo 2>&1 | \
172
+ egrep -q '(^| )installed'; then
173
+ apt-get install -y -q some_package_name < /dev/null
174
+ done
175
+
176
+ Now compare that hideous command to the simple, clear and consistent AutomateIt command before it. AutomateIt's plugins and drivers are easy to install and write. As more are written, more people will hopefully be freed from needlessly convoluted low-level commands, and able to get simple things done simply. AutomateIt's consistent API, multiple drivers, sane defaults and conditional-checking make it easier to write clear and maintainable recipes than using the low-level directly commands from the Unix shell.
177
+
178
+ === Driver auto-detection
179
+
180
+ AutomateIt can automatically detect the most suitable driver for each plugin command.
181
+
182
+ For example, the AutomateIt::PackageManager plugin has drivers called AutomateIt::PackageManager::APT and AutomateIt::PackageManager::YUM. On a Debian system, which uses the <tt>apt-get</tt> packaging tool, AutomateIt will default to using the AutomateIt::PackageManager::APT driver:
183
+
184
+ ai> package_manager.installed? "apache2"
185
+ => true
186
+
187
+ === Using a specific driver
188
+
189
+ Sometimes it's necessary to specify the driver to use. The recommended way to do this is to pass a <tt>:with => :driver_name</tt> option to the plugin command.
190
+
191
+ For example, tell the package manager to use the Gem driver:
192
+
193
+ ai> package_manager.installed? "automateit", :with => :gem
194
+ => true
195
+
196
+ You can also completely bypass the plugin and its auto-detection to directly interact with the driver:
197
+
198
+ ai> package_manager[:gem].installed? "automateit"
199
+ => true
200
+
201
+ === Projects
202
+
203
+ A project is a special directory that contains related recipes and helper files. Although it's possible to run recipe files without a project, a project provides many useful features, described in the AutomateIt::Project documentation.
204
+
205
+ A project is created by specifying the directory to create:
206
+
207
+ you@host:tmp> cd /tmp
208
+ you@host:tmp> automateit --create myproject
209
+ ** mkdir -p myproject
210
+ => Creating AutomateIt project at: myproject
211
+ ** cd myproject
212
+ ** mkdir config
213
+ ** cd config
214
+ => Rendering 'tags.yml' because of it doesn't exist
215
+ => Rendering 'fields.yml' because of it doesn't exist
216
+ => Rendering 'automateit_env.rb' because of it doesn't exist
217
+ ** cd -
218
+ ** mkdir dist
219
+ ** cd dist
220
+ => Rendering 'README.txt' because of it doesn't exist
221
+ ** cd -
222
+ ** mkdir lib
223
+ ** cd lib
224
+ => Rendering 'README.txt' because of it doesn't exist
225
+ ** cd -
226
+ ** mkdir recipes
227
+ ** cd recipes
228
+ => Rendering 'README.txt' because of it doesn't exist
229
+ ** cd -
230
+ => DONE!
231
+
232
+ This creates a <tt>/tmp/myproject</tt> directory with the newly-created project. It contains directories, each with a <tt>README.txt</tt> file explaining the directory's purpose, and individual files like <tt>tags.yml</tt> that contain comments with basic usage instructions.
233
+
234
+ The project creator is an AutomateIt recipe, so it's smart enough to only execute the commands needed. If the project creator is re-run against an existing project, it won't make any changes because none are needed:
235
+
236
+ you@host:tmp> automateit --create myproject
237
+ => Found AutomateIt project at: myproject
238
+ => DONE!
239
+
240
+ === Project recipes
241
+
242
+ To associate a recipe with a project, put it into the project's +recipes+ directory.
243
+
244
+ For example, create a <tt>recipes/hello_project.rb</tt> file with these contents:
245
+
246
+ puts "Hello, this is: " + project
247
+
248
+ And run it:
249
+
250
+ you@host:myproject> automateit recipes/hello_project.rb
251
+ Hello, this is: /tmp/myproject
252
+
253
+ The Interpreter automatically loads the project. The +project+ method contains the project path and is only available when executing a recipe associated with a project.
254
+
255
+ === Fields
256
+
257
+ A project's <tt>config/fields.yml</tt> file is meant to store configuration constants, like custom paths for applications. Fields abstract configuration variables for recipes, improving maintainability by separating data and logic. Fields can also be easily queried from Unix using the +aifield+ command. More information about fields and +aifield+ can be found in AutomateIt::FieldManager.
258
+
259
+ For example, consider a fields file with the following contents:
260
+
261
+ myuser: dhh
262
+ myapp:
263
+ path: /var/www/rails
264
+
265
+ These fields can be used from the interactive shell like this:
266
+
267
+ you@host:myproject> pwd
268
+ /tmp/myproject
269
+ you@host:myproject> automateit -p . # (1) Load project from current directory
270
+ => AutomateIt Shell v0.5.0
271
+ ai> lookup :myuser # (2) Lookup string value by symbol key
272
+ => "dhh"
273
+ ai> lookup "myuser" # (3) Lookup string value by string key
274
+ => "dhh"
275
+ ai> lookup "myapp" # (4) Lookup hash value by string key
276
+ => {"path"=>"/var/www/rails"}
277
+ ai> lookup "myapp#path" # (5) Lookup string value by compound key
278
+ => "/var/www/rails"
279
+
280
+ To load a project's fields, the AutomateIt interactive shell needs to know which project to load. On the line annotated (1), <tt>automateit -p .</tt> tells it to load the project from the "." directory, the current directory. The argument can be an absolute or relative path. The command accepts other arguments and environmental options, run <tt>automateit --help</tt> for details.
281
+
282
+ Fields can be queried by string (2) or symbol (3) keys. The +lookup+ command can return any associated data, usually a string, but it can be a complex type, such as a hash (4). The compound-key (5) syntax is a convenient syntax for looking up nested keys in a hash. For example, <tt>lookup "myapp#path"</tt> is a shortcut for <tt>lookup("myapp")["path"] -- these query the +myapp+ hash and return the value of its +path+ key.
283
+
284
+ The Interpreter loads a project and its fields automatically for recipes, so there is no need to specify the <tt>-p</tt> option. For example, a project recipe file <tt>recipes/hello_fields.rb</tt> contains:
285
+
286
+ puts lookup("myapp#path")
287
+
288
+ This recipe will load its project and fields automatically:
289
+
290
+ you@host:myproject> automateit recipes/hello_fields.rb
291
+ /var/www/rails
292
+
293
+ === Tags
294
+
295
+ A project's <tt>config/tags.yml</tt> file describes tags assigned to hosts, grouping together hosts by their roles and attributes.
296
+
297
+ For example, this tags file describes a "desktops" tag with three hosts named "satori", "sunyata" and "michiru", and another tag named "notebooks" with other hosts:
298
+ desktops:
299
+ - satori
300
+ - sunyata
301
+ - michiru
302
+ notebooks:
303
+ - rheya
304
+ - avijja
305
+
306
+ The tags can be accessed like this when run on a host named "satori":
307
+
308
+ you@satori:myproject> automateit -p .
309
+ ai> tags
310
+ => ["satori", "desktops", "localhost", ...] # Tags for this host
311
+ ai> tagged?("desktops") # Is this host tagged with "desktops"?
312
+ => true
313
+ ai> tagged?("notebooks")
314
+ => false
315
+ ai> tagged?(:satori) # Strings and symbols are treated the same.
316
+ => true
317
+ ai> tagged?("satori")
318
+ => true
319
+ ai> tagged?("satori || desktops") # Query by simple boolean expression
320
+ => true
321
+ ai> tagged?("(satori || desktops) && !notebooks") # Query by complex boolean expression
322
+ => true
323
+
324
+ Role-based behavior can be demonstrated by creating a file called <tt>recipes/hello_tags.rb</tt>:
325
+
326
+ if tagged?("localhost")
327
+ puts "I'm a localhost!"
328
+ end
329
+ if tagged?("desktops")
330
+ puts "Special commands to execute on desktops"
331
+ elsif tagged?("notebooks")
332
+ puts "Special commands to execute on notebooks"
333
+ end
334
+
335
+ Here are the results when executed on a host called "satori":
336
+
337
+ you@satori:myproject> automateit recipes/hello_tags.rb
338
+ I'm a localhost!
339
+ Special commands to execute on desktops
340
+
341
+ Notice how the +notebooks+ section wasn't executed? Tags make it possible to create sophisticated recipes that run commands on only the appropriate systems.
342
+
343
+ More documentation on tags can be found in AutomateIt::TagManager.
344
+
345
+ === Previewing commands
346
+
347
+ AutomateIt lets you preview commands the recipe will run without actually letting them actually modify the system.
348
+
349
+ The Interpreter has a boolean that determines if it'll make changes to your system. This one variable can be called from two different ways:
350
+ * <tt>writing?</tt> -- Will it write changes?
351
+ * <tt>noop?</tt> -- Will it not write changes and just preview them? The +noop+ means "no-operation"
352
+
353
+ Here's an example with the interactive shell, with comments for annotations:
354
+
355
+ ai> noop true # Enter noop mode
356
+ ai> noop? # Currently in noop mode?
357
+ => true # Yes, in noop mode
358
+ ai> writing? # Writing to disk? The opposite of noop
359
+ => false # No, not writing
360
+ ai> mkdir "foo" # Try to create a directory
361
+ ** mkdir foo # Message showing directory will be creating
362
+ => ["foo"] # Return value with directories to create
363
+ ai> File.directory? "foo" # Was the directory actually made?
364
+ => false # No, noop mode prevented the change
365
+
366
+ Recipes can take advantage of the noop mode as well, consider a <tt>mkdir_example.rb</tt> recipe:
367
+
368
+ mkdir "foo"
369
+
370
+ To run this recipe with noop mode, pass the <tt>-n</tt> option to the Interpreter shell:
371
+
372
+ you@host:tmp> automateit -n mkdir_example.rb
373
+ ** mkdir foo
374
+ you@host:tmp> ls foo
375
+ ls: foo: No such file or directory
376
+
377
+ Notice how the directory wasn't actually created? This is great because you can see exactly what commands AutomateIt will run without actually having it apply the changes.
378
+
379
+ *WARNING*: Previewing code can be dangerous. Read
380
+ previews.txt[link:files/docs/previews_txt.html] for instructions on how to
381
+ write code that can be safely previewed.
382
+
383
+ === Conclusion
384
+
385
+ I hope you enjoy working with AutomateIt and look forward to hearing about your
386
+ experiences with it. Drivers, patches, documentation and ideas are welcome.
387
+
388
+ Thank you for taking the time to read this!
389
+
390
+ - Igal Koshevoy (igal@pragmaticraft.com)