├── .ansible-lint ├── .editorconfig ├── .github └── workflows │ └── ansible-linting-check.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── defaults └── main.yml ├── handlers └── main.yml ├── meta └── main.yml ├── tasks ├── main.yml ├── reboot.yml └── unattended-upgrades.yml ├── templates ├── auto-upgrades.j2 └── unattended-upgrades.j2 ├── tests ├── ansible.cfg ├── inventory ├── requirements.yml ├── test.sh └── test.yml └── vars ├── Debian-bullseye.yml ├── Debian-wheezy.yml ├── Debian.yml └── Ubuntu.yml /.ansible-lint: -------------------------------------------------------------------------------- 1 | skip_list: 2 | - '503' 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.github/workflows/ansible-linting-check.yml: -------------------------------------------------------------------------------- 1 | name: Ansible Lint check 2 | # visit https://github.com/marketplace/actions/ansible-lint for infos 3 | 4 | on: [push, pull_request] 5 | 6 | jobs: 7 | build: 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | 14 | - name: Lint Ansible Playbook 15 | uses: ansible/ansible-lint-action@master 16 | with: 17 | targets: "." 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ 2 | *~ 3 | *.log 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: python 3 | services: docker 4 | 5 | cache: pip 6 | 7 | install: 8 | - pip install ansible docker 9 | - ansible-galaxy install -r tests/requirements.yml -p tests/roles/ 10 | 11 | script: 12 | - ansible --version 13 | - tests/test.sh 14 | 15 | notifications: 16 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ⚠️ **This role is deprecated!** See the [GitHub issue for explanation](https://github.com/jnv/ansible-role-unattended-upgrades/issues/98) and [maintained fork](https://github.com/hifis-net/ansible-role-unattended-upgrades) of this role. 2 | 3 | # Unattended-Upgrades Role for Ansible 4 | 5 | [![Build Status of branch master](https://img.shields.io/travis/jnv/ansible-role-unattended-upgrades/master.svg?style=flat-square)](https://travis-ci.org/jnv/ansible-role-unattended-upgrades) 6 | [![Ansible Role: jnv.unattended-upgrades](https://img.shields.io/ansible/role/8068.svg?style=flat-square)](https://galaxy.ansible.com/jnv/unattended-upgrades/) 7 | 8 | Install and setup [unattended-upgrades](https://launchpad.net/unattended-upgrades) for Ubuntu and Debian (since Wheezy), to periodically install security upgrades. 9 | 10 | **NOTE:** If you have used version 0.0.1 of the role, you can delete the file `/etc/apt/apt.conf.d/10periodic` as it is not needed anymore. You can use the following one-shot command: 11 | 12 | ansible -m file -a "state=absent path=/etc/apt/apt.conf.d/10periodic" 13 | 14 | ## Requirements 15 | 16 | The role uses [apt module](http://docs.ansible.com/apt_repository_module.html) which has additional dependencies. 17 | 18 | If you set `unattended_mail` to an e-mail address, make sure `mailx` command is available and your system is able to send e-mails. 19 | 20 | The role requires unattended-upgrades version 0.70 and newer, which is available since Debian Wheezy and Ubuntu 12.04 respectively. This is due to [Origins Patterns](#origins-patterns) usage; if this is not available on your system, you may use [the first version of the role](https://github.com/jnv/ansible-role-unattended-upgrades/tree/v0.1). 21 | 22 | ### Automatic Reboot 23 | 24 | If you enable automatic reboot feature (`unattended_automatic_reboot`), the role will attempt to install `update-notifier-common` package, which is required on some systems for detecting and executing reboot after the upgrade. You may optionally define a specific time for rebooting (`unattended_automatic_reboot_time`). 25 | 26 | This feature was broken in Debian Jessie, but eventually was rolled into the unattended-upgrades package; see [the discussion in #6](https://github.com/jnv/ansible-role-unattended-upgrades/issues/6) for more details. 27 | 28 | ## Disabled Cron Jobs 29 | 30 | On some hosts you may find that the unattended-upgrade's cronfile `/etc/cron.daily/apt` file has been renamed to `apt.disabled`. This is possibly provider's decision, to save some CPU cycles. Use [enable-standard-cronjobs](https://github.com/Yannik/ansible-role-enable-standard-cronjobs) role to reenable unattended-upgrades. See also discussion in [#9](https://github.com/jnv/ansible-role-unattended-upgrades/issues/9). 31 | 32 | ## Role Variables 33 | 34 | * `unattended_cache_valid_time`: Update the apt cache if its older than the given time in seconds; passed to the [apt module](https://docs.ansible.com/ansible/latest/apt_module.html) during package installation. 35 | * Default: `3600` 36 | * `unattended_origins_patterns`: array of origins patterns to determine whether the package can be automatically installed, for more details see [Origins Patterns](#origins-patterns) below. 37 | * Default for Debian: `['origin=Debian,codename=${distro_codename},label=Debian-Security']` 38 | * Default for Ubuntu: `['origin=Ubuntu,archive=${distro_codename}-security,label=Ubuntu']` 39 | * `unattended_package_blacklist`: packages which won't be automatically upgraded 40 | * Default: `[]` 41 | * `unattended_autofix_interrupted_dpkg`: whether on unclean dpkg exit to run `dpkg --force-confold --configure -a` 42 | * Default: `true` 43 | * `unattended_minimal_steps`: split the upgrade into the smallest possible chunks so that they can be interrupted with SIGUSR1. 44 | * Default: `true` 45 | * `unattended_install_on_shutdown`: install all unattended-upgrades when the machine is shuting down. 46 | * Default: `false` 47 | * `unattended_mail`: e-mail address to send information about upgrades or problems with unattended upgrades 48 | * Default: `false` (don't send any e-mail) 49 | * `unattended_mail_only_on_error`: send e-mail only on errors, otherwise e-mail will be sent every time there's a package upgrade. 50 | * Default: `false` 51 | * `unattended_remove_unused_dependencies`: do automatic removal of all unused dependencies after the upgrade. 52 | * Default: `false` 53 | * `unattended_remove_new_unused_dependencies`: do automatic removal of new unused dependencies after the upgrade. 54 | * Default: `true` 55 | * `unattended_automatic_reboot`: Automatically reboot system if any upgraded package requires it, immediately after the upgrade. 56 | * Default: `false` 57 | * `unattended_automatic_reboot_time`: Automatically reboot system if any upgraded package requires it, at the specific time (_HH:MM_) instead of immediately after the upgrade. 58 | * Default: `false` 59 | * `unattended_update_days`: Set the days of the week that updates should be applied. The days can be specified as localized abbreviated or full names. Or as integers where "0" is Sunday, "1" is Monday etc. Example: `{"Mon";"Fri"};` 60 | * Default: disabled 61 | * `unattended_ignore_apps_require_restart`: unattended-upgrades won't automatically upgrade some critical packages requiring restart after an upgrade (i.e. there is `XB-Upgrade-Requires: app-restart` directive in their debian/control file). With this option set to `true`, unattended-upgrades will upgrade these packages regardless of the directive. 62 | * Default: `false` 63 | * `unattended_syslog_enable`: Write events to syslog, which is useful in environments where syslog messages are sent to a central store. 64 | * Default: `false` 65 | * `unattended_syslog_facility`: Write events to the specified syslog facility, or the daemon facility if not specified. Will only have affect if `unattended_syslog_enable` is set to `true`. 66 | * Default: `daemon` 67 | * `unattended_verbose`: Define verbosity level of APT for periodic runs. The output will be sent to root. 68 | * Possible options: 69 | * `0`: no report 70 | * `1`: progress report 71 | * `2`: + command outputs 72 | * `3`: + trace on 73 | * Default: `0` (no report) 74 | * `unattended_update_package_list`: Do "apt-get update" automatically every n-days (0=disable) 75 | * Default: `1` 76 | * `unattended_download_upgradeable`: Do "apt-get upgrade --download-only" every n-days (0=disable) 77 | * Default: `0` 78 | * `unattended_autoclean_interval`: Do "apt-get autoclean" every n-days (0=disable) 79 | * Default: `7` 80 | * `unattended_clean_interval`: Do "apt-get clean" every n-days (0=disable) 81 | * Default: `0` 82 | * `unattended_random_sleep`: Define maximum for a random interval in seconds after which the apt job starts (only for systems without systemd) 83 | * Default: `1800` (30 minutes) 84 | * `unattended_dpkg_options`: Array of dpkg command-line options used during unattended-upgrades runs, e.g. `["--force-confdef"]`, `["--force-confold"]` 85 | * Default: `[]` 86 | * `unattended_dl_limit`: Limit the download speed in kb/sec using apt bandwidth limit feature. 87 | * Default: disabled 88 | * `unattended_only_on_ac_power`: Download and install upgrades only on AC power. It will also install the debian package `powermgmt-base`. 89 | * Default: false 90 | 91 | ## Origins Patterns 92 | 93 | Origins Pattern is a more powerful alternative to the Allowed Origins option used in previous versions of unattended-upgrade. 94 | 95 | Pattern is composed from specific keywords: 96 | 97 | * `a`,`archive`,`suite` – e.g. `stable`, `trusty-security` (`archive=stable`) 98 | * `c`,`component` – e.g. `main`, `crontrib`, `non-free` (`component=main`) 99 | * `l`,`label` – e.g. `Debian`, `Debian-Security`, `Ubuntu` 100 | * `o`,`origin` – e.g. `Debian`, `Unofficial Multimedia Packages`, `Ubuntu` 101 | * `n`,`codename` – e.g. `jessie`, `jessie-updates`, `trusty` (this is only supported with `unattended-upgrades` >= 0.80) 102 | * `site` – e.g. `http.debian.net` 103 | 104 | You can review the available repositories using `apt-cache policy` and debug your choice using `unattended-upgrades -d` command on a target system. 105 | 106 | Additionally unattended-upgrades support two macros (variables), derived from `/etc/debian_version`: 107 | 108 | * `${distro_id}` – Installed distribution name, e.g. `Debian` or `Ubuntu`. 109 | * `${distro_codename}` – Installed codename, e.g. `jessie` or `trusty`. 110 | 111 | Using `${distro_codename}` should be preferred over using `stable` or `oldstable` as a selected, as once `stable` moves to `oldstable`, no security updates will be installed at all, or worse, package from a newer distro release will be installed by accident. The same goes for upgrading your installation from `oldstable` to `stable`, if you forget to change this in your origin patterns, you may not receive the security updates for your newer distro release. With `${distro_codename}`, both cases can never happen. 112 | 113 | ## Role Usage Examples 114 | 115 | Example for Ubuntu, with custom [origins patterns](#patterns-examples), blacklisted packages and e-mail notification: 116 | 117 | ```yaml 118 | - hosts: all 119 | roles: 120 | - role: jnv.unattended-upgrades 121 | unattended_origins_patterns: 122 | - 'origin=Ubuntu,archive=${distro_codename}-security' 123 | - 'o=Ubuntu,a=${distro_codename}-updates' 124 | unattended_package_blacklist: [cowsay, vim] 125 | unattended_mail: 'root@example.com' 126 | ``` 127 | 128 | _Note:_ You don't need to specify `unattended_origins_patterns`, the role will use distribution's default if the variable is not set. 129 | 130 | ### Running Only on Debian-based Systems 131 | 132 | If you manage multiple distribution with the same playbook, you may want to skip running this role on non-Debian systems. You can [use `when` conditional with role](https://docs.ansible.com/ansible/latest/user_guide/playbooks_conditionals.html#conditionals-with-roles) to limit the role to particular systems: 133 | 134 | ```yaml 135 | - hosts: all 136 | roles: 137 | - role: jnv.unattended-upgrades 138 | when: ansible_facts['os_family'] == 'Debian' 139 | ``` 140 | 141 | See [#38](https://github.com/jnv/ansible-role-unattended-upgrades/pull/38) for discussion. 142 | 143 | ### Patterns Examples 144 | 145 | By default, only security updates are allowed for both Ubuntu and Debian. You can add more patterns to allow unattended-updates install more packages automatically, however be aware that automated major updates may potentially break your system. 146 | 147 | #### For Debian 148 | 149 | ```yaml 150 | unattended_origins_patterns: 151 | - 'origin=Debian,codename=${distro_codename},label=Debian-Security' # security updates 152 | - 'o=Debian,codename=${distro_codename},label=Debian' # updates including non-security updates 153 | - 'o=Debian,codename=${distro_codename},a=proposed-updates' 154 | ``` 155 | 156 | On debian wheezy, due to `unattended-upgrades` being `0.79.5`, you cannot use the `codename` directive. 157 | 158 | You will have to do archive based matching instead: 159 | 160 | ```yaml 161 | unattended_origins_patterns: 162 | - 'origin=Debian,a=stable,label=Debian-Security' # security updates 163 | - 'o=Debian,a=stable,l=Debian' # updates including non-security updates 164 | - 'o=Debian,a=proposed-updates' 165 | ``` 166 | 167 | Please be sure to read about the issues regarding this in the origin pattern documentation above. 168 | 169 | #### For Ubuntu 170 | 171 | In Ubuntu, archive always contains the distribution codename 172 | 173 | ```yaml 174 | unattended_origins_patterns: 175 | - 'origin=Ubuntu,archive=${distro_codename}-security' 176 | - 'o=Ubuntu,a=${distro_codename}' 177 | - 'o=Ubuntu,a=${distro_codename}-updates' 178 | - 'o=Ubuntu,a=${distro_codename}-proposed-updates' 179 | ``` 180 | 181 | 182 | #### For Raspbian 183 | 184 | In Raspbian, it is only possible to update all packages from the default repository, including non-security updates, or updating none. 185 | 186 | Updating all, including non-security: 187 | 188 | ```yaml 189 | unattended_origins_patterns: 190 | - 'origin=Raspbian,codename=${distro_codename},label=Raspbian' 191 | ``` 192 | 193 | You can not use the `codename` directive on raspbian wheezy, the same as with debian wheezy above. 194 | 195 | To not install any updates on a raspbian host, just set `unattended_origins_patterns` to an empty list: 196 | ``` 197 | unattended_origins_patterns: [] 198 | ``` 199 | 200 | 201 | ## License 202 | 203 | GPLv2 204 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Cache update time for apt module 3 | unattended_cache_valid_time: 3600 4 | 5 | #Unattended-Upgrade::Origins-Pattern 6 | # Automatically upgrade packages from these origin patterns 7 | # e.g.: 'o=Debian,a=stable', 'o=Debian,a=stable-updates' 8 | # 9 | # Left unset, distribution-specific defaults will be used through 10 | # __unattended_origins_patterns variable only if this variable 11 | # is not provided externally 12 | # REFS https://github.com/ansible/ansible/issues/8121 13 | #unattended_origins_patterns: [] 14 | 15 | #Unattended-Upgrade::Package-Blacklist 16 | # List of packages to not update 17 | unattended_package_blacklist: [] 18 | 19 | #Unattended-Upgrade::AutoFixInterruptedDpkg 20 | # On a unclean dpkg exit unattended-upgrades will run 21 | # dpkg --force-confold --configure -a 22 | # The default is true, to ensure updates keep getting installed 23 | unattended_autofix_interrupted_dpkg: true 24 | 25 | #Unattended-Upgrade::MinimalSteps 26 | # Split the upgrade into the smallest possible chunks so that 27 | # they can be interrupted with SIGUSR1. This makes the upgrade 28 | # a bit slower but it has the benefit that shutdown while a upgrade 29 | # is running is possible (with a small delay) 30 | unattended_minimal_steps: true 31 | 32 | #Unattended-Upgrade::InstallOnShutdown 33 | # Install all unattended-upgrades when the machine is shuting down 34 | # instead of doing it in the background while the machine is running 35 | # This will (obviously) make shutdown slower 36 | unattended_install_on_shutdown: false 37 | 38 | #Unattended-Upgrade::Mail 39 | # Send email to this address for problems or packages upgrades 40 | # If empty or unset then no email is sent, make sure that you 41 | # have a working mail setup on your system. A package that provides 42 | # 'mailx' must be installed. 43 | unattended_mail: false 44 | 45 | #Unattended-Upgrade::MailOnlyOnError 46 | # Set this value to "true" to get emails only on errors. Default 47 | # is to always send a mail if Unattended-Upgrade::Mail is set 48 | unattended_mail_only_on_error: false 49 | 50 | #Unattended-Upgrade::Remove-Unused-Dependencies 51 | # Do automatic removal of all unused dependencies after the upgrade 52 | # (equivalent to apt-get autoremove) 53 | unattended_remove_unused_dependencies: false 54 | 55 | #Unattended-Upgrade::Remove-New-Unused-Dependencies 56 | # Remove any new unused dependencies after the upgrade 57 | unattended_remove_new_unused_dependencies: true 58 | 59 | #Unattended-Upgrade::Automatic-Reboot 60 | # Automatically reboot *WITHOUT CONFIRMATION* if a 61 | # the file /var/run/reboot-required is found after the upgrade 62 | unattended_automatic_reboot: false 63 | 64 | #Unattended-Upgrade::Automatic-Reboot-Time 65 | # If automatic reboot is enabled and needed, reboot at the specific 66 | # time instead of immediately 67 | unattended_automatic_reboot_time: false 68 | 69 | #Unattended-Upgrade::IgnoreAppsRequireRestart 70 | # Do upgrade application even if it requires restart after upgrade 71 | # I.e. "XB-Upgrade-Requires: app-restart" is set in the debian/control file 72 | unattended_ignore_apps_require_restart: false 73 | 74 | #Unattended-Upgrade::SyslogEnable 75 | # Write events to syslog, which is useful in environments where syslog 76 | # messages are sent to a central store. 77 | unattended_syslog_enable: false 78 | 79 | #Unattended-Upgrade::SyslogFacility 80 | # Write events to the specified syslog facility, or the daemon facility if 81 | # not specified. Requires the Unattended-Upgrade::SyslogEnable option to be 82 | # set to true. 83 | #unattended_syslog_facility: "daemon" 84 | 85 | ### APT::Periodic configuration 86 | # Snatched from /usr/lib/apt/apt.systemd.daily 87 | 88 | #APT::Periodic::Update-Package-Lists "0"; 89 | # - Do "apt-get update" automatically every n-days (0=disable) 90 | unattended_update_package_list: 1 91 | 92 | #APT::Periodic::Download-Upgradeable-Packages "0"; 93 | # - Do "apt-get upgrade --download-only" every n-days (0=disable) 94 | #unattended_download_upgradeable: 0 95 | 96 | #APT::Periodic::AutocleanInterval "0"; 97 | # - Do "apt-get autoclean" every n-days (0=disable) 98 | unattended_autoclean_interval: 7 99 | 100 | #APT::Periodic::CleanInterval "0"; 101 | # - Do "apt-get clean" every n-days (0=disable) 102 | #unattended_clean_interval: 0 103 | 104 | #APT::Periodic::Verbose "0"; 105 | # - Send report mail to root 106 | # 0: no report (or null string) 107 | # 1: progress report (actually any string) 108 | # 2: + command outputs (remove -qq, remove 2>/dev/null, add -d) 109 | # 3: + trace on 110 | #unattended_verbose: 0 111 | 112 | ## Cron systems only 113 | 114 | #APT::Periodic::RandomSleep 115 | # When the apt job starts, it will sleep for a random period between 0 116 | # and APT::Periodic::RandomSleep seconds 117 | # The default value is "1800" so that the script will stall for up to 30 118 | # minutes (1800 seconds) so that the mirror servers are not crushed by 119 | # everyone running their updates all at the same time 120 | # Kept undefined to allow default (1800) 121 | #unattended_random_sleep: 0 122 | 123 | #Dpkg::Options 124 | # Provide dpkg options that take effect during unattended upgrades. 125 | # By default no flags are appended. Configuration file changes can 126 | # block installation of certain packages. Passing the flags 127 | # "--force-confdef" and "--force-confold" will ensure updates are applied 128 | # and old configuration files are preserved. 129 | unattended_dpkg_options: [] 130 | 131 | # unattended_dpkg_options: 132 | # - "--force-confdef" 133 | # - "--force-confold" 134 | 135 | 136 | # Use apt bandwidth limit feature, this example limits the download speed to 70kb/sec 137 | #unattended_dl_limit: 70 138 | 139 | # Unattended-Upgrade::OnlyOnACPower 140 | # Download and install upgrades only on AC power 141 | # (i.e. skip or gracefully stop updates on battery) 142 | unattended_only_on_ac_power: false 143 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for unattended-upgrades 3 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Jan Vlnas 4 | description: Setup unattended-upgrades on Debian-based systems 5 | license: GPLv2 6 | min_ansible_version: 1.4 7 | platforms: 8 | - name: Ubuntu 9 | versions: 10 | - precise 11 | - raring 12 | - saucy 13 | - trusty 14 | - utopic 15 | - name: Debian 16 | versions: 17 | - wheezy 18 | - jessie 19 | - buster 20 | - bullseye 21 | # 22 | # Below are all categories currently available. Just as with 23 | # the platforms above, uncomment those that apply to your role. 24 | # 25 | galaxy_tags: 26 | #- cloud 27 | #- cloud:ec2 28 | #- cloud:gce 29 | #- cloud:rax 30 | #- database 31 | #- database:nosql 32 | #- database:sql 33 | #- development 34 | #- monitoring 35 | #- networking 36 | #- packaging 37 | - system 38 | #- web 39 | dependencies: [] 40 | 41 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | - include: unattended-upgrades.yml 2 | tags: unattended 3 | -------------------------------------------------------------------------------- /tasks/reboot.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Ignored, since newer distros don't need this package 3 | # https://github.com/jnv/ansible-role-unattended-upgrades/issues/6 4 | - name: install update-notifier-common 5 | apt: 6 | pkg: update-notifier-common 7 | state: present 8 | failed_when: false 9 | 10 | -------------------------------------------------------------------------------- /tasks/unattended-upgrades.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: add distribution-specific variables 3 | include_vars: "{{ ansible_distribution }}.yml" 4 | 5 | - name: add Debian Wheezy workaround 6 | include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml" 7 | when: (ansible_distribution == "Debian") and (ansible_distribution_release == "wheezy") 8 | 9 | - name: add Debian Bullseye workaround 10 | include_vars: "{{ ansible_distribution }}-{{ ansible_distribution_release }}.yml" 11 | when: (ansible_distribution == "Debian") and (ansible_distribution_release == "bullseye") 12 | 13 | - name: install powermgmt-base 14 | apt: 15 | pkg: 16 | state: present 17 | cache_valid_time: "{{ unattended_cache_valid_time }}" 18 | update_cache: yes 19 | when: unattended_only_on_ac_power 20 | 21 | - name: install unattended-upgrades 22 | apt: 23 | pkg: unattended-upgrades 24 | state: present 25 | cache_valid_time: "{{ unattended_cache_valid_time }}" 26 | update_cache: yes 27 | 28 | - name: install reboot dependencies 29 | include: reboot.yml 30 | when: unattended_automatic_reboot|bool 31 | 32 | - name: create APT auto-upgrades configuration 33 | template: 34 | src: auto-upgrades.j2 35 | dest: /etc/apt/apt.conf.d/20auto-upgrades 36 | owner: root 37 | group: root 38 | mode: 0644 39 | 40 | - name: create unattended-upgrades configuration 41 | template: 42 | src: unattended-upgrades.j2 43 | dest: /etc/apt/apt.conf.d/50unattended-upgrades 44 | owner: root 45 | group: root 46 | mode: 0644 47 | -------------------------------------------------------------------------------- /templates/auto-upgrades.j2: -------------------------------------------------------------------------------- 1 | {{ ansible_managed | comment('c') }} 2 | 3 | APT::Periodic::Unattended-Upgrade "1"; 4 | 5 | {% if unattended_update_package_list is defined %} 6 | APT::Periodic::Update-Package-Lists "{{unattended_update_package_list}}"; 7 | {% endif %} 8 | 9 | {% if unattended_download_upgradeable is defined %} 10 | APT::Periodic::Download-Upgradeable-Packages "{{unattended_download_upgradeable}}"; 11 | {% endif %} 12 | 13 | {% if unattended_autoclean_interval is defined %} 14 | APT::Periodic::AutocleanInterval "{{unattended_autoclean_interval}}"; 15 | {% endif %} 16 | 17 | {% if unattended_clean_interval is defined %} 18 | APT::Periodic::CleanInterval "{{unattended_clean_interval}}"; 19 | {% endif %} 20 | 21 | {% if unattended_verbose is defined %} 22 | APT::Periodic::Verbose "{{unattended_verbose}}"; 23 | {% endif %} 24 | 25 | {% if unattended_random_sleep is defined %} 26 | APT::Periodic::RandomSleep "{{unattended_random_sleep}}"; 27 | {% endif %} 28 | -------------------------------------------------------------------------------- /templates/unattended-upgrades.j2: -------------------------------------------------------------------------------- 1 | {{ ansible_managed | comment('c') }} 2 | 3 | // Unattended-Upgrade::Origins-Pattern controls which packages are 4 | // upgraded. 5 | Unattended-Upgrade::Origins-Pattern { 6 | {% if unattended_origins_patterns is defined %} 7 | {% for origin in unattended_origins_patterns %} 8 | "{{ origin }}"; 9 | {% endfor %} 10 | {% else %} 11 | {% for origin in __unattended_origins_patterns %} 12 | "{{ origin }}"; 13 | {% endfor %} 14 | {% endif %} 15 | }; 16 | 17 | // List of packages to not update (regexp are supported) 18 | Unattended-Upgrade::Package-Blacklist { 19 | {% for package in unattended_package_blacklist %} 20 | "{{package}}"; 21 | {% endfor %} 22 | }; 23 | 24 | {% if not unattended_autofix_interrupted_dpkg %} 25 | // This option allows you to control if on a unclean dpkg exit 26 | // unattended-upgrades will automatically run 27 | // dpkg --force-confold --configure -a 28 | // The default is true, to ensure updates keep getting installed 29 | Unattended-Upgrade::AutoFixInterruptedDpkg "false"; 30 | {% endif %} 31 | 32 | // Split the upgrade into the smallest possible chunks so that 33 | // they can be interrupted with SIGUSR1. This makes the upgrade 34 | // a bit slower but it has the benefit that shutdown while a upgrade 35 | // is running is possible (with a small delay) 36 | Unattended-Upgrade::MinimalSteps "{{ unattended_minimal_steps | lower }}"; 37 | 38 | {% if unattended_install_on_shutdown %} 39 | // Install all unattended-upgrades when the machine is shuting down 40 | // instead of doing it in the background while the machine is running 41 | // This will (obviously) make shutdown slower 42 | Unattended-Upgrade::InstallOnShutdown "true"; 43 | {% endif %} 44 | 45 | {% if unattended_mail %} 46 | // Send email to this address for problems or packages upgrades 47 | // If empty or unset then no email is sent, make sure that you 48 | // have a working mail setup on your system. A package that provides 49 | // 'mailx' must be installed. 50 | Unattended-Upgrade::Mail "{{unattended_mail}}"; 51 | {% endif %} 52 | 53 | {% if unattended_mail_only_on_error %} 54 | // Set this value to "true" to get emails only on errors. Default 55 | // is to always send a mail if Unattended-Upgrade::Mail is set 56 | Unattended-Upgrade::MailOnlyOnError "true"; 57 | {% endif %} 58 | 59 | {% if unattended_remove_unused_dependencies %} 60 | // Do automatic removal of all unused dependencies after the upgrade 61 | // (equivalent to apt-get autoremove) 62 | Unattended-Upgrade::Remove-Unused-Dependencies "true"; 63 | {% endif %} 64 | 65 | {% if not unattended_remove_new_unused_dependencies %} 66 | // Do automatic removal of new unused dependencies after the upgrade 67 | Unattended-Upgrade::Remove-New-Unused-Dependencies "false"; 68 | {% endif %} 69 | 70 | {% if unattended_automatic_reboot %} 71 | // Automatically reboot *WITHOUT CONFIRMATION* if a 72 | // the file /var/run/reboot-required is found after the upgrade 73 | Unattended-Upgrade::Automatic-Reboot "true"; 74 | {% endif %} 75 | 76 | {% if unattended_automatic_reboot_time %} 77 | // If automatic reboot is enabled and needed, reboot at the specific 78 | // time instead of immediately 79 | // Default: "now" 80 | Unattended-Upgrade::Automatic-Reboot-Time "{{ unattended_automatic_reboot_time }}"; 81 | {% endif %} 82 | 83 | {% if unattended_update_days is defined %} 84 | // Set the days of the week that updates should be applied. The days can be specified 85 | // as localized abbreviated or full names. Or as integers where "0" is Sunday, "1" is 86 | // Monday etc. 87 | // Example - apply updates only on Monday and Friday: 88 | // {"Mon";"Fri"}; 89 | Unattended-Upgrade::Update-Days {{ unattended_update_days }}; 90 | {% endif %} 91 | 92 | {% if unattended_ignore_apps_require_restart %} 93 | // Do upgrade application even if it requires restart after upgrade 94 | // I.e. "XB-Upgrade-Requires: app-restart" is set in the debian/control file 95 | Unattended-Upgrade::IgnoreAppsRequireRestart "true"; 96 | {% endif %} 97 | 98 | {% if unattended_syslog_enable %} 99 | // Write events to syslog, which is useful in environments where syslog 100 | // messages are sent to a central store. 101 | Unattended-Upgrade::SyslogEnable "{{ unattended_syslog_enable }}"; 102 | {% if unattended_syslog_facility is defined %} 103 | // Write events to the specified syslog facility, or the daemon facility 104 | // if not specified. Requires the Unattended-Upgrade::SyslogEnable option 105 | // to be set to true. 106 | Unattended-Upgrade::SyslogFacility "{{ unattended_syslog_facility }}"; 107 | {% endif %} 108 | {% endif %} 109 | 110 | {% if unattended_dpkg_options %} 111 | // Append options for governing dpkg behavior, e.g. --force-confdef. 112 | Dpkg::Options { 113 | {% for dpkg_option in unattended_dpkg_options %} 114 | "{{ dpkg_option }}"; 115 | {% endfor %} 116 | }; 117 | {% endif %} 118 | 119 | {% if unattended_dl_limit is defined %} 120 | // Use apt bandwidth limit feature, this example limits the download 121 | // speed to 70kb/sec 122 | Acquire::http::Dl-Limit "{{ unattended_dl_limit }}"; 123 | {% endif %} 124 | 125 | // Download and install upgrades only on AC power 126 | // (i.e. skip or gracefully stop updates on battery) 127 | Unattended-Upgrade::OnlyOnACPower "{{ unattended_only_on_ac_power }}"; 128 | -------------------------------------------------------------------------------- /tests/ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | roles_path = ../../ 3 | retry_files_enabled = False 4 | -------------------------------------------------------------------------------- /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost ansible_connection=local ansible_python_interpreter="/usr/bin/env python" 2 | -------------------------------------------------------------------------------- /tests/requirements.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - src: chrismeyersfsu.provision_docker 3 | name: provision_docker 4 | -------------------------------------------------------------------------------- /tests/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Exit on any individual command failure 4 | set -e 5 | 6 | # Pretty colors. 7 | red='\033[0;31m' 8 | green='\033[0;32m' 9 | neutral='\033[0m' 10 | 11 | section() { 12 | echo -e "\033[33;1m$1\033[0m" 13 | } 14 | 15 | fold_start() { 16 | echo -e "travis_fold:start:$1\033[33;1m$2\033[0m" 17 | } 18 | 19 | fold_end() { 20 | echo -e "\ntravis_fold:end:$1\r" 21 | } 22 | 23 | # Ensure we are in the tests dir 24 | cd "$( dirname "${BASH_SOURCE[0]}" )" 25 | 26 | section "Syntax check" 27 | ansible-playbook -i inventory --syntax-check test.yml 28 | section "Running role" 29 | ansible-playbook -i inventory test.yml 30 | -------------------------------------------------------------------------------- /tests/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Bring up Docker containers 3 | hosts: localhost 4 | gather_facts: false 5 | vars: 6 | inventory: 7 | - name: ubuntu_latest 8 | image: "ubuntu:latest" 9 | - name: ubuntu_bionic 10 | image: "ubuntu:bionic" 11 | - name: ubuntu_xenial 12 | image: "ubuntu:xenial" 13 | - name: ubuntu_trusty 14 | image: "ubuntu:trusty" 15 | # 6/2020: Disabled Debian Testing due to missing python packages (python-apt) 16 | #- name: debian_testing 17 | # image: "debian:testing" 18 | - name: debian_stable 19 | image: "debian:stable" 20 | - name: debian_oldstable 21 | image: "debian:oldstable" 22 | roles: 23 | - role: provision_docker 24 | provision_docker_inventory: "{{ inventory }}" 25 | provision_docker_privileged: true 26 | provision_docker_use_docker_connection: true 27 | 28 | - name: Test role 29 | hosts: docker_containers 30 | gather_facts: false 31 | pre_tasks: 32 | - name: Provision Python 33 | raw: bash -c "test -e /usr/bin/python || (apt-get -y update && apt-get install -y python)" 34 | register: output 35 | changed_when: output.stdout 36 | - name: Gather facts 37 | setup: 38 | vars: 39 | unattended_autofix_interrupted_dpkg: false 40 | unattended_minimal_steps: true 41 | unattended_install_on_shutdown: true 42 | unattended_automatic_reboot: true 43 | unattended_update_days: '{"Sat"}' 44 | roles: 45 | # Searched for in ../.. (see ansible.cfg) 46 | - ansible-role-unattended-upgrades 47 | tasks: 48 | - name: Idempotency check 49 | include_role: 50 | name: ansible-role-unattended-upgrades 51 | register: idempotency 52 | - name: fail when idempotency.changed 53 | fail: 54 | msg: Role failed idempotency check 55 | when: idempotency.changed 56 | 57 | - name: Get apt-config variables 58 | command: apt-config dump 59 | register: aptconfig 60 | changed_when: false 61 | - name: Check for registered variables 62 | assert: 63 | that: item in aptconfig.stdout 64 | with_items: 65 | - 'APT::Periodic::Unattended-Upgrade "1"' 66 | - 'Unattended-Upgrade::AutoFixInterruptedDpkg "false"' 67 | - 'Unattended-Upgrade::MinimalSteps "true"' 68 | - 'Unattended-Upgrade::InstallOnShutdown "true"' 69 | - 'Unattended-Upgrade::Automatic-Reboot "true"' 70 | # NOTE: this uses the array syntax, which requires one 71 | # top-level record, then one item per line 72 | - 'Unattended-Upgrade::Update-Days "";' 73 | - 'Unattended-Upgrade::Update-Days:: "Sat";' 74 | 75 | - name: Dry run unattended-upgrades 76 | command: /usr/bin/unattended-upgrades --dry-run 77 | changed_when: idempotency.changed|bool 78 | -------------------------------------------------------------------------------- /vars/Debian-bullseye.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # From https://metadata.ftp-master.debian.org/changelogs//main/u/unattended-upgrades/unattended-upgrades_2.8_changelog 3 | # Allow both ${distro_codename} or ${distro_codename}-security on Debian 4 | # as security update codenames. The latter will be used starting with 5 | # Bullseye, but to help backporting and testing the configuration file keeps 6 | # working on Buster and older releases. (Closes: #933138) 7 | __unattended_origins_patterns: 8 | - 'origin=Debian,codename=${distro_codename},label=Debian-Security' 9 | - 'origin=Debian,codename=${distro_codename}-security,label=Debian-Security' 10 | -------------------------------------------------------------------------------- /vars/Debian-wheezy.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # This workaround for Debian Wheezy which doesn't support ${distro_codename} macro 4 | # See 5 | # https://github.com/jnv/ansible-role-unattended-upgrades/issues/19 6 | # https://github.com/jnv/ansible-role-unattended-upgrades/pull/20 7 | # for details 8 | 9 | __unattended_origins_patterns: 10 | - 'origin=Debian,archive=stable,label=Debian-Security' 11 | - 'origin=Debian,archive=oldstable,label=Debian-Security' 12 | -------------------------------------------------------------------------------- /vars/Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | __unattended_origins_patterns: 3 | - 'origin=Debian,codename=${distro_codename},label=Debian-Security' 4 | -------------------------------------------------------------------------------- /vars/Ubuntu.yml: -------------------------------------------------------------------------------- 1 | --- 2 | __unattended_origins_patterns: 3 | - 'origin=Ubuntu,archive=${distro_codename}-security,label=Ubuntu' 4 | --------------------------------------------------------------------------------