├── .coveralls.yml ├── spec ├── fixtures │ └── unit │ │ └── puppet │ │ └── provider │ │ └── sysctl │ │ └── augeas │ │ ├── empty │ │ ├── small │ │ ├── broken │ │ └── full ├── spec_helper_acceptance.rb ├── spec_helper.rb ├── unit │ └── puppet │ │ ├── type │ │ └── sysctl_spec.rb │ │ └── provider │ │ └── sysctl │ │ └── augeas_spec.rb └── acceptance │ └── sysctl_spec.rb ├── .gitmodules ├── .fixtures.yml ├── .msync.yml ├── .github ├── labeler.yml ├── workflows │ ├── labeler.yml │ ├── ci.yml │ ├── release.yml │ └── prepare_release.yml ├── PULL_REQUEST_TEMPLATE.md ├── ISSUE_TEMPLATE.md └── release.yml ├── .puppet-lint.rc ├── .rubocop.yml ├── .editorconfig ├── .gitignore ├── .sync.yml ├── .pmtignore ├── Gemfile ├── Rakefile ├── .travis.sh ├── .overcommit.yml ├── HISTORY.md ├── metadata.json ├── REFERENCE.md ├── .rubocop_todo.yml ├── lib └── puppet │ ├── type │ └── sysctl.rb │ └── provider │ └── sysctl │ └── augeas.rb ├── README.md ├── CHANGELOG.md └── LICENSE /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci 2 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/sysctl/augeas/empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "augeas"] 2 | path = augeas 3 | url = https://github.com/hercules-team/augeas.git 4 | -------------------------------------------------------------------------------- /.fixtures.yml: -------------------------------------------------------------------------------- 1 | --- 2 | fixtures: 3 | repositories: 4 | augeasproviders_core: https://github.com/voxpupuli/puppet-augeasproviders_core 5 | -------------------------------------------------------------------------------- /.msync.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | modulesync_config_version: '10.3.0' 6 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | skip-changelog: 6 | - head-branch: ['^release-*', 'release'] 7 | -------------------------------------------------------------------------------- /.puppet-lint.rc: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | 4 | --fail-on-warnings 5 | --no-parameter_documentation-check 6 | --no-parameter_types-check 7 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | inherit_from: .rubocop_todo.yml 6 | inherit_gem: 7 | voxpupuli-test: rubocop.yml 8 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/sysctl/augeas/small: -------------------------------------------------------------------------------- 1 | # Kernel sysctl configuration file 2 | # 3 | # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and 4 | # sysctl.conf(5) for more details. 5 | 6 | # Controls IP packet forwarding 7 | net.ipv4.ip_forward = 0 8 | 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | # Managed by modulesync - DO NOT EDIT 4 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 5 | 6 | root = true 7 | 8 | [*] 9 | charset = utf-8 10 | end_of_line = lf 11 | indent_size = 2 12 | tab_width = 2 13 | indent_style = space 14 | insert_final_newline = true 15 | trim_trailing_whitespace = true 16 | -------------------------------------------------------------------------------- /spec/spec_helper_acceptance.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Managed by modulesync - DO NOT EDIT 4 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 5 | 6 | require 'voxpupuli/acceptance/spec_helper_acceptance' 7 | 8 | configure_beaker(modules: :metadata) 9 | 10 | Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | 4 | /pkg/ 5 | /Gemfile.lock 6 | /Gemfile.local 7 | /vendor/ 8 | /.vendor/ 9 | /spec/fixtures/manifests/ 10 | /spec/fixtures/modules/ 11 | /.vagrant/ 12 | /.bundle/ 13 | /.ruby-version 14 | /coverage/ 15 | /log/ 16 | /.idea/ 17 | /.dependencies/ 18 | /.librarian/ 19 | /Puppetfile.lock 20 | *.iml 21 | .*.sw? 22 | /.yardoc/ 23 | /Guardfile 24 | bolt-debug.log 25 | .rerun.json 26 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | name: "Pull Request Labeler" 6 | 7 | # yamllint disable-line rule:truthy 8 | on: 9 | pull_request_target: {} 10 | 11 | permissions: 12 | contents: read 13 | pull-requests: write 14 | 15 | jobs: 16 | labeler: 17 | permissions: 18 | contents: read 19 | pull-requests: write 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/labeler@v5 23 | -------------------------------------------------------------------------------- /.sync.yml: -------------------------------------------------------------------------------- 1 | --- 2 | .github/workflows/ci.yml: 3 | with: 4 | additional_packages: libaugeas-dev augeas-tools 5 | rubocop: false 6 | Gemfile: 7 | optional: 8 | ':test': 9 | - gem: ruby-augeas 10 | spec/spec_helper.rb: 11 | spec_overrides: 12 | - "require 'augeas_spec'" 13 | - "require 'fixtures/modules/augeasproviders_core/spec/support/spec/psh_fixtures'" 14 | - "# augeasproviders: setting $LOAD_PATH to work around broken type autoloading" 15 | - "$LOAD_PATH.unshift(File.join(__dir__, 'fixtures/modules/augeasproviders_core/lib'))" 16 | spec/spec_helper_acceptance.rb: 17 | unmanaged: false 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 9 | #### Pull Request (PR) description 10 | 13 | 14 | #### This Pull Request (PR) fixes the following issues 15 | 21 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | name: CI 6 | 7 | # yamllint disable-line rule:truthy 8 | on: 9 | pull_request: {} 10 | push: 11 | branches: 12 | - main 13 | - master 14 | 15 | concurrency: 16 | group: ${{ github.ref_name }} 17 | cancel-in-progress: true 18 | 19 | permissions: 20 | contents: read 21 | 22 | jobs: 23 | puppet: 24 | name: Puppet 25 | uses: voxpupuli/gha-puppet/.github/workflows/beaker.yml@v3 26 | with: 27 | additional_packages: 'libaugeas-dev augeas-tools' 28 | rubocop: false 29 | -------------------------------------------------------------------------------- /.pmtignore: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | 4 | /docs/ 5 | /pkg/ 6 | /Gemfile 7 | /Gemfile.lock 8 | /Gemfile.local 9 | /vendor/ 10 | /.vendor/ 11 | /spec/ 12 | /Rakefile 13 | /.vagrant/ 14 | /.bundle/ 15 | /.ruby-version 16 | /coverage/ 17 | /log/ 18 | /.idea/ 19 | /.dependencies/ 20 | /.github/ 21 | /.librarian/ 22 | /Puppetfile.lock 23 | /Puppetfile 24 | *.iml 25 | /.editorconfig 26 | /.fixtures.yml 27 | /.gitignore 28 | /.msync.yml 29 | /.overcommit.yml 30 | /.pmtignore 31 | /.rspec 32 | /.rspec_parallel 33 | /.rubocop.yml 34 | /.sync.yml 35 | .*.sw? 36 | /.yardoc/ 37 | /.yardopts 38 | /Dockerfile 39 | /HISTORY.md 40 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | name: Release 6 | 7 | # yamllint disable-line rule:truthy 8 | on: 9 | push: 10 | tags: 11 | - '*' 12 | 13 | permissions: 14 | contents: write 15 | 16 | jobs: 17 | release: 18 | name: Release 19 | uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v3 20 | with: 21 | allowed_owner: 'voxpupuli' 22 | secrets: 23 | # Configure secrets here: 24 | # https://docs.github.com/en/actions/security-guides/encrypted-secrets 25 | username: ${{ secrets.PUPPET_FORGE_USERNAME }} 26 | api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | ## Affected Puppet, Ruby, OS and module versions/distributions 12 | 13 | - Puppet: 14 | - Ruby: 15 | - Distribution: 16 | - Module version: 17 | 18 | ## How to reproduce (e.g Puppet code you use) 19 | 20 | ## What are you seeing 21 | 22 | ## What behaviour did you expect instead 23 | 24 | ## Output log 25 | 26 | ## Any additional information you'd like to impart 27 | -------------------------------------------------------------------------------- /.github/workflows/prepare_release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | name: 'Prepare Release' 6 | 7 | on: 8 | workflow_dispatch: 9 | inputs: 10 | version: 11 | description: 'Module version to be released. Must be a valid semver string without leading v. (1.2.3)' 12 | required: false 13 | 14 | permissions: 15 | contents: write 16 | pull-requests: write 17 | 18 | jobs: 19 | release_prep: 20 | uses: 'voxpupuli/gha-puppet/.github/workflows/prepare_release.yml@v3' 21 | with: 22 | version: ${{ github.event.inputs.version }} 23 | allowed_owner: 'voxpupuli' 24 | secrets: 25 | # Configure secrets here: 26 | # https://docs.github.com/en/actions/security-guides/encrypted-secrets 27 | github_pat: '${{ secrets.PCCI_PAT_RELEASE_PREP }}' 28 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/sysctl/augeas/broken: -------------------------------------------------------------------------------- 1 | broken file = 2 | # Kernel sysctl configuration file 3 | # 4 | # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and 5 | # sysctl.conf(5) for more details. 6 | 7 | # Controls IP packet forwarding 8 | net.ipv4.ip_forward = 0 9 | 10 | # Controls source route verification 11 | net.ipv4.conf.default.rp_filter = 1 12 | 13 | # Do not accept source routing 14 | net.ipv4.conf.default.accept_source_route = 0 15 | 16 | # Controls the System Request debugging functionality of the kernel 17 | kernel.sysrq = 0 18 | 19 | # Controls whether core dumps will append the PID to the core filename. 20 | # Useful for debugging multi-threaded applications. 21 | kernel.core_uses_pid = 1 22 | 23 | # Disable netfilter on bridges. 24 | net.bridge.bridge-nf-call-ip6tables = 0 25 | net.bridge.bridge-nf-call-iptables = 0 26 | net.bridge.bridge-nf-call-arptables = 0 27 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | 4 | source ENV['GEM_SOURCE'] || 'https://rubygems.org' 5 | 6 | group :test do 7 | gem 'voxpupuli-test', '~> 13.0', :require => false 8 | gem 'puppet_metadata', '~> 5.0', :require => false 9 | gem 'ruby-augeas', :require => false 10 | end 11 | 12 | group :development do 13 | gem 'guard-rake', :require => false 14 | gem 'overcommit', '>= 0.39.1', :require => false 15 | end 16 | 17 | group :system_tests do 18 | gem 'voxpupuli-acceptance', '~> 4.0', :require => false 19 | end 20 | 21 | group :release do 22 | gem 'voxpupuli-release', '~> 5.0', :require => false 23 | end 24 | 25 | gem 'rake', :require => false 26 | 27 | gem 'openvox', ENV.fetch('OPENVOX_GEM_VERSION', [">= 7", "< 9"]), :require => false, :groups => [:test] 28 | 29 | # vim: syntax=ruby 30 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/sysctl/augeas/full: -------------------------------------------------------------------------------- 1 | # Kernel sysctl configuration file 2 | # 3 | # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and 4 | # sysctl.conf(5) for more details. 5 | 6 | # Controls IP packet forwarding 7 | net.ipv4.ip_forward = 0 8 | 9 | # Controls source route verification 10 | net.ipv4.conf.default.rp_filter = 1 11 | 12 | # net.ipv4.conf.default.accept_source_route: Do not accept source routing 13 | net.ipv4.conf.default.accept_source_route = 0 14 | 15 | # SysRq setting 16 | # kernel.sysrq: controls the System Request debugging functionality of the kernel 17 | kernel.sysrq = 0 18 | 19 | # Controls whether core dumps will append the PID to the core filename. 20 | # Useful for debugging multi-threaded applications. 21 | kernel.core_uses_pid = 1 22 | 23 | # Disable netfilter on bridges. 24 | net.bridge.bridge-nf-call-ip6tables = 0 25 | #net.bridge.bridge-nf-call-iptables = 0 26 | net.bridge.bridge-nf-call-arptables = 0 27 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | # https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes 6 | 7 | changelog: 8 | exclude: 9 | labels: 10 | - duplicate 11 | - invalid 12 | - modulesync 13 | - question 14 | - skip-changelog 15 | - wont-fix 16 | - wontfix 17 | 18 | categories: 19 | - title: Breaking Changes 🛠 20 | labels: 21 | - backwards-incompatible 22 | 23 | - title: New Features 🎉 24 | labels: 25 | - enhancement 26 | 27 | - title: Bug Fixes 🐛 28 | labels: 29 | - bug 30 | 31 | - title: Documentation Updates 📚 32 | labels: 33 | - documentation 34 | - docs 35 | 36 | - title: Dependency Updates ⬆️ 37 | labels: 38 | - dependencies 39 | 40 | - title: Other Changes 41 | labels: 42 | - "*" 43 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | 4 | begin 5 | require 'voxpupuli/test/rake' 6 | rescue LoadError 7 | # only available if gem group test is installed 8 | end 9 | 10 | begin 11 | require 'voxpupuli/acceptance/rake' 12 | rescue LoadError 13 | # only available if gem group acceptance is installed 14 | end 15 | 16 | begin 17 | require 'voxpupuli/release/rake_tasks' 18 | rescue LoadError 19 | # only available if gem group releases is installed 20 | else 21 | GCGConfig.user = 'voxpupuli' 22 | GCGConfig.project = 'puppet-augeasproviders_sysctl' 23 | end 24 | 25 | desc "Run main 'test' task and report merged results to coveralls" 26 | task test_with_coveralls: [:test] do 27 | if Dir.exist?(File.expand_path('../lib', __FILE__)) 28 | require 'coveralls/rake/task' 29 | Coveralls::RakeTask.new 30 | Rake::Task['coveralls:push'].invoke 31 | else 32 | puts 'Skipping reporting to coveralls. Module has no lib dir' 33 | end 34 | end 35 | 36 | # vim: syntax=ruby 37 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Managed by modulesync - DO NOT EDIT 4 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 5 | 6 | # puppetlabs_spec_helper will set up coverage if the env variable is set. 7 | # We want to do this if lib exists and it hasn't been explicitly set. 8 | ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) 9 | 10 | require 'voxpupuli/test/spec_helper' 11 | 12 | RSpec.configure do |c| 13 | c.facterdb_string_keys = false 14 | end 15 | 16 | add_mocked_facts! 17 | 18 | if File.exist?(File.join(__dir__, 'default_module_facts.yml')) 19 | facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) 20 | facts&.each do |name, value| 21 | add_custom_fact name.to_sym, value 22 | end 23 | end 24 | 25 | require 'augeas_spec' 26 | 27 | require 'fixtures/modules/augeasproviders_core/spec/support/spec/psh_fixtures' 28 | 29 | # augeasproviders: setting $LOAD_PATH to work around broken type autoloading 30 | 31 | $LOAD_PATH.unshift(File.join(__dir__, 'fixtures/modules/augeasproviders_core/lib')) 32 | Dir['./spec/support/spec/**/*.rb'].sort.each { |f| require f } 33 | -------------------------------------------------------------------------------- /.travis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -xe 3 | 4 | # Clone submodules in tree 5 | git submodule update --init 6 | 7 | if [ -z $AUGEAS ]; then 8 | # Use latest version of lenses 9 | cd augeas && git pull origin master 10 | PKG_VERSION="" 11 | else 12 | if [ -z $LENSES ]; then 13 | # Use matching version of lenses 14 | cd augeas && git fetch && git checkout release-${AUGEAS} 15 | else 16 | cd augeas && git fetch && git checkout $LENSES 17 | fi 18 | 19 | PKG_VERSION="=${AUGEAS}*" 20 | # Add PPA 21 | sudo add-apt-repository -y ppa:raphink/augeas-1.0.0 22 | sudo add-apt-repository -y ppa:raphink/augeas-1.1.0 23 | sudo add-apt-repository -y ppa:raphink/augeas-1.2.0 24 | sudo add-apt-repository -y ppa:raphink/augeas-1.3.0 25 | fi 26 | sudo add-apt-repository -y ppa:raphink/augeas 27 | sudo apt-get update 28 | sudo apt-get install augeas-tools${PKG_VERSION} \ 29 | augeas-lenses${PKG_VERSION} \ 30 | libaugeas0${PKG_VERSION} \ 31 | libaugeas-dev${PKG_VERSION} \ 32 | libxml2-dev 33 | 34 | # Install gems 35 | gem install bundler 36 | bundle install 37 | 38 | # Reporting only 39 | bundle show 40 | puppet --version 41 | augtool --version 42 | -------------------------------------------------------------------------------- /.overcommit.yml: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | # 4 | # Hooks are only enabled if you take action. 5 | # 6 | # To enable the hooks run: 7 | # 8 | # ``` 9 | # bundle exec overcommit --install 10 | # # ensure .overcommit.yml does not harm to you and then 11 | # bundle exec overcommit --sign 12 | # ``` 13 | # 14 | # (it will manage the .git/hooks directory): 15 | # 16 | # Examples howto skip a test for a commit or push: 17 | # 18 | # ``` 19 | # SKIP=RuboCop git commit 20 | # SKIP=PuppetLint git commit 21 | # SKIP=RakeTask git push 22 | # ``` 23 | # 24 | # Don't invoke overcommit at all: 25 | # 26 | # ``` 27 | # OVERCOMMIT_DISABLE=1 git commit 28 | # ``` 29 | # 30 | # Read more about overcommit: https://github.com/brigade/overcommit 31 | # 32 | # To manage this config yourself in your module add 33 | # 34 | # ``` 35 | # .overcommit.yml: 36 | # unmanaged: true 37 | # ``` 38 | # 39 | # to your modules .sync.yml config 40 | --- 41 | PreCommit: 42 | RuboCop: 43 | enabled: true 44 | description: 'Runs rubocop on modified files only' 45 | command: ['bundle', 'exec', 'rubocop'] 46 | RakeTarget: 47 | enabled: true 48 | description: 'Runs lint on modified files only' 49 | targets: 50 | - 'lint' 51 | command: ['bundle', 'exec', 'rake'] 52 | YamlSyntax: 53 | enabled: true 54 | JsonSyntax: 55 | enabled: true 56 | TrailingWhitespace: 57 | enabled: true 58 | 59 | PrePush: 60 | RakeTarget: 61 | enabled: true 62 | description: 'Run rake targets' 63 | targets: 64 | - 'validate' 65 | - 'test' 66 | - 'rubocop' 67 | command: ['bundle', 'exec', 'rake'] 68 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | ## 2.6.2 2 | 3 | - Add support for augeasproviders_core 3 4 | - Add support for puppet 7 5 | - Fix OpenBSD support 6 | - Fix handling of entries with the 'target' specified 7 | - Fix bug in sysctl arguments on FreeBSD 8 | 9 | ## 2.6.1 10 | 11 | - Optimize provider resource creation during prefetch to reduce system load 12 | - Fix support for OpenBSD 13 | 14 | ## 2.6.0 15 | 16 | - FreeBSD: skip read-only MIB data (GH #48) 17 | 18 | ## 2.5.1 19 | 20 | - Force data read from 'sysctl -a' into ASCSII (GH #46) 21 | 22 | ## 2.5.0 23 | 24 | - Add support for: 25 | - Debian 10 26 | - EL 8 27 | 28 | ## 2.4.0 29 | 30 | - Add Archlinux support (GH #38) 31 | - Use : as separator on FreeBSD (fix #24) (GH #30) 32 | - Do not manage comment when persist is false (fix #29) (GH #31) 33 | 34 | ## 2.3.1 35 | 36 | - Fix puppet requirement to < 7.0.0 37 | 38 | ## 2.3.0 39 | 40 | - Add support for Puppet 6 41 | - Deprecate support for Puppet < 5 42 | - Update supported OSes in metadata.json 43 | 44 | ## 2.2.1 45 | - Added support for Puppet 5 and OEL 46 | 47 | ## 2.2.0 48 | - Removed Travis tests for Puppet < 4.7 since that is the most common LTS 49 | release and Puppet 3 is well out of support 50 | - Added OpenBSD and FreeBSD to the compatibility list 51 | - Added a :persist option for enabling saving to the /etc/sysctl.conf file 52 | - Added the capability to update either the live value *or* the disk value 53 | independently 54 | - Now use prefetching to get the sysctl values 55 | - Updated self.instances to obtain information about *all* sysctl values which 56 | provides a more accurate representation of the system when using `puppet 57 | resource` 58 | - Updated all tests 59 | 60 | ## 2.1.0 61 | - Added a :silent option for deliberately ignoring failures when applying the 62 | live sysctl setting. 63 | - Added acceptance tests 64 | 65 | ## 2.0.2 66 | 67 | - Improve Gemfile 68 | - Do not version Gemfile.lock 69 | - Add badges to README 70 | - Munge values to strings 71 | - Add specs for the sysctl type 72 | 73 | ## 2.0.1 74 | 75 | - Convert specs to rspec3 syntax 76 | - Fix metadata.json 77 | 78 | ## 2.0.0 79 | 80 | - First release of split module. 81 | -------------------------------------------------------------------------------- /metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "puppet-augeasproviders_sysctl", 3 | "version": "3.3.1-rc0", 4 | "author": "Vox Pupuli", 5 | "summary": "Augeas-based sysctl type and provider for Puppet", 6 | "license": "Apache-2.0", 7 | "source": "https://github.com/voxpupuli/puppet-augeasproviders_sysctl", 8 | "project_page": "https://github.com/voxpupuli/puppet-augeasproviders_sysctl", 9 | "issues_url": "https://github.com/voxpupuli/puppet-augeasproviders_sysctl/issues", 10 | "dependencies": [ 11 | { 12 | "name": "puppet/augeasproviders_core", 13 | "version_requirement": ">= 3.2.1 < 5.0.0" 14 | } 15 | ], 16 | "operatingsystem_support": [ 17 | { 18 | "operatingsystem": "Debian", 19 | "operatingsystemrelease": [ 20 | "10", 21 | "11", 22 | "12", 23 | "13" 24 | ] 25 | }, 26 | { 27 | "operatingsystem": "Ubuntu", 28 | "operatingsystemrelease": [ 29 | "18.04", 30 | "20.04", 31 | "22.04", 32 | "24.04" 33 | ] 34 | }, 35 | { 36 | "operatingsystem": "RedHat", 37 | "operatingsystemrelease": [ 38 | "7", 39 | "8", 40 | "9" 41 | ] 42 | }, 43 | { 44 | "operatingsystem": "CentOS", 45 | "operatingsystemrelease": [ 46 | "7", 47 | "8", 48 | "9" 49 | ] 50 | }, 51 | { 52 | "operatingsystem": "OracleLinux", 53 | "operatingsystemrelease": [ 54 | "7", 55 | "8", 56 | "9" 57 | ] 58 | }, 59 | { 60 | "operatingsystem": "Rocky", 61 | "operatingsystemrelease": [ 62 | "8", 63 | "9" 64 | ] 65 | }, 66 | { 67 | "operatingsystem": "AlmaLinux", 68 | "operatingsystemrelease": [ 69 | "8", 70 | "9" 71 | ] 72 | }, 73 | { 74 | "operatingsystem": "OpenSUSE", 75 | "operatingsystemrelease": [ 76 | "15.4" 77 | ] 78 | }, 79 | { 80 | "operatingsystem": "FreeBSD", 81 | "operatingsystemrelease": [ 82 | "12", 83 | "13" 84 | ] 85 | }, 86 | { 87 | "operatingsystem": "OpenBSD", 88 | "operatingsystemrelease": [ 89 | "7" 90 | ] 91 | }, 92 | { 93 | "operatingsystem": "Archlinux" 94 | } 95 | ], 96 | "requirements": [ 97 | { 98 | "name": "openvox", 99 | "version_requirement": ">= 8.19.0 < 9.0.0" 100 | } 101 | ] 102 | } 103 | -------------------------------------------------------------------------------- /spec/unit/puppet/type/sysctl_spec.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rspec 2 | 3 | require 'spec_helper' 4 | 5 | sysctl_type = Puppet::Type.type(:sysctl) 6 | 7 | describe sysctl_type do 8 | context 'when setting parameters' do 9 | describe 'the name parameter' do 10 | it 'is a valid parameter' do 11 | resource = sysctl_type.new name: 'foo' 12 | expect(resource[:name]).to eq('foo') 13 | end 14 | end 15 | 16 | describe 'the val property' do 17 | it 'is a valid property' do 18 | resource = sysctl_type.new name: 'foo', val: 'foo' 19 | expect(resource[:val]).to eq('foo') 20 | end 21 | 22 | it 'is munged to a string' do 23 | resource = sysctl_type.new name: 'foo', val: 42 24 | expect(resource[:val]).to eq('42') 25 | end 26 | end 27 | 28 | describe 'the value property' do 29 | it 'is a valid property' do 30 | resource = sysctl_type.new name: 'foo', value: 'foo' 31 | expect(resource[:value]).to eq('foo') 32 | end 33 | 34 | it 'is munged to a string' do 35 | resource = sysctl_type.new name: 'foo', value: 42 36 | expect(resource[:value]).to eq('42') 37 | end 38 | end 39 | 40 | describe 'the target parameter' do 41 | it 'is a valid parameter' do 42 | resource = sysctl_type.new name: 'foo', target: '/foo/bar' 43 | expect(resource[:target]).to eq('/foo/bar') 44 | end 45 | end 46 | 47 | describe 'the apply parameter' do 48 | it 'is a valid parameter' do 49 | resource = sysctl_type.new name: 'foo', apply: :false 50 | expect(resource[:apply]).to eq(:false) 51 | end 52 | 53 | it 'defaults to true' do 54 | resource = sysctl_type.new name: 'foo' 55 | expect(resource[:apply]).to eq(:true) 56 | end 57 | 58 | it 'is munged as a boolean' do 59 | resource = sysctl_type.new name: 'foo', apply: 'true' 60 | expect(resource[:apply]).to eq(:true) 61 | end 62 | end 63 | 64 | describe 'the persist parameter' do 65 | it 'is a valid parameter' do 66 | resource = sysctl_type.new name: 'foo', persist: :false 67 | expect(resource[:persist]).to eq(:false) 68 | end 69 | 70 | it 'defaults to true' do 71 | resource = sysctl_type.new name: 'foo' 72 | expect(resource[:persist]).to eq(:true) 73 | end 74 | 75 | it 'is munged as a boolean' do 76 | resource = sysctl_type.new name: 'foo', persist: 'true' 77 | expect(resource[:persist]).to eq(:true) 78 | end 79 | end 80 | end 81 | end 82 | -------------------------------------------------------------------------------- /REFERENCE.md: -------------------------------------------------------------------------------- 1 | # Reference 2 | 3 | 4 | 5 | ## Table of Contents 6 | 7 | ### Resource types 8 | 9 | * [`sysctl`](#sysctl): Manages entries in /etc/sysctl.conf. 10 | 11 | ## Resource types 12 | 13 | ### `sysctl` 14 | 15 | Manages entries in /etc/sysctl.conf. 16 | 17 | #### Properties 18 | 19 | The following properties are available in the `sysctl` type. 20 | 21 | ##### `comment` 22 | 23 | Text to be stored in a comment immediately above the entry. It will be automatically prepended with the name of the setting in order for the provider to know whether it controls the comment or not. 24 | 25 | ##### `ensure` 26 | 27 | Valid values: `present`, `absent` 28 | 29 | The basic property that the resource should be in. 30 | 31 | Default value: `present` 32 | 33 | ##### `val` 34 | 35 | An alias for 'value'. Maintains interface compatibility with the traditional ParsedFile sysctl provider. If both are set, 'value' will take precedence over 'val'. 36 | 37 | ##### `value` 38 | 39 | Value to change the setting to. Settings with multiple values (such as net.ipv4.tcp_mem) are represented as a single whitespace separated string. 40 | 41 | #### Parameters 42 | 43 | The following parameters are available in the `sysctl` type. 44 | 45 | * [`apply`](#-sysctl--apply) 46 | * [`name`](#-sysctl--name) 47 | * [`persist`](#-sysctl--persist) 48 | * [`provider`](#-sysctl--provider) 49 | * [`silent`](#-sysctl--silent) 50 | * [`target`](#-sysctl--target) 51 | 52 | ##### `apply` 53 | 54 | Valid values: `true`, `false` 55 | 56 | Whether to apply the value using the sysctl command. 57 | 58 | Default value: `true` 59 | 60 | ##### `name` 61 | 62 | namevar 63 | 64 | The name of the setting, e.g. net.ipv4.ip_forward 65 | 66 | ##### `persist` 67 | 68 | Valid values: `true`, `false` 69 | 70 | Persist the value in the on-disk file ($target). 71 | 72 | Default value: `true` 73 | 74 | ##### `provider` 75 | 76 | The specific backend to use for this `sysctl` resource. You will seldom need to specify this --- Puppet will usually 77 | discover the appropriate provider for your platform. 78 | 79 | ##### `silent` 80 | 81 | Valid values: `true`, `false` 82 | 83 | If set, do not report an error if the system key does not exist. This is useful for systems that may need to load a 84 | kernel module prior to the sysctl values existing. 85 | 86 | Default value: `false` 87 | 88 | ##### `target` 89 | 90 | The file in which to store the settings, defaults to 91 | `/etc/sysctl.conf`. 92 | 93 | -------------------------------------------------------------------------------- /.rubocop_todo.yml: -------------------------------------------------------------------------------- 1 | # This configuration was generated by 2 | # `rubocop --auto-gen-config` 3 | # on 2023-08-17 21:30:11 UTC using RuboCop version 1.50.2. 4 | # The point is for the user to remove these configuration records 5 | # one by one as the offenses are removed from the code base. 6 | # Note that changes in the inspected code, or installation of new 7 | # versions of RuboCop, may require this file to be generated again. 8 | 9 | # Offense count: 1 10 | # This cop supports unsafe autocorrection (--autocorrect-all). 11 | # Configuration parameters: AllowSafeAssignment. 12 | Lint/AssignmentInCondition: 13 | Exclude: 14 | - 'lib/puppet/provider/sysctl/augeas.rb' 15 | 16 | # Offense count: 1 17 | # Configuration parameters: AllowedMethods. 18 | # AllowedMethods: enums 19 | Lint/ConstantDefinitionInBlock: 20 | Exclude: 21 | - 'lib/puppet/type/sysctl.rb' 22 | 23 | # Offense count: 1 24 | # Configuration parameters: AllowKeywordBlockArguments. 25 | Lint/UnderscorePrefixedVariableName: 26 | Exclude: 27 | - 'lib/puppet/type/sysctl.rb' 28 | 29 | # Offense count: 1 30 | Lint/UselessAssignment: 31 | Exclude: 32 | - 'lib/puppet/provider/sysctl/augeas.rb' 33 | 34 | # Offense count: 2 35 | # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. 36 | # AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to 37 | Naming/MethodParameterName: 38 | Exclude: 39 | - 'lib/puppet/type/sysctl.rb' 40 | 41 | # Offense count: 2 42 | RSpec/BeforeAfterAll: 43 | Exclude: 44 | - 'spec/acceptance/**/*' 45 | - 'spec/unit/puppet/provider/sysctl/augeas_spec.rb' 46 | 47 | # Offense count: 8 48 | RSpec/ExpectInHook: 49 | Exclude: 50 | - 'spec/unit/puppet/provider/sysctl/augeas_spec.rb' 51 | 52 | # Offense count: 20 53 | # Configuration parameters: AssignmentOnly. 54 | RSpec/InstanceVariable: 55 | Exclude: 56 | - 'spec/unit/puppet/provider/sysctl/augeas_spec.rb' 57 | 58 | # Offense count: 56 59 | # Configuration parameters: . 60 | # SupportedStyles: have_received, receive 61 | RSpec/MessageSpies: 62 | EnforcedStyle: receive 63 | 64 | # Offense count: 1 65 | RSpec/PendingWithoutReason: 66 | Exclude: 67 | - 'spec/unit/puppet/provider/sysctl/augeas_spec.rb' 68 | 69 | # Offense count: 26 70 | RSpec/StubbedMock: 71 | Exclude: 72 | - 'spec/unit/puppet/provider/sysctl/augeas_spec.rb' 73 | 74 | # Offense count: 5 75 | # This cop supports unsafe autocorrection (--autocorrect-all). 76 | # Configuration parameters: EnforcedStyle. 77 | # SupportedStyles: always, always_true, never 78 | Style/FrozenStringLiteralComment: 79 | Exclude: 80 | - 'lib/puppet/provider/sysctl/augeas.rb' 81 | - 'lib/puppet/type/sysctl.rb' 82 | - 'spec/acceptance/sysctl_spec.rb' 83 | - 'spec/unit/puppet/provider/sysctl/augeas_spec.rb' 84 | - 'spec/unit/puppet/type/sysctl_spec.rb' 85 | 86 | # Offense count: 1 87 | # This cop supports unsafe autocorrection (--autocorrect-all). 88 | # Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. 89 | # AllowedMethods: present?, blank?, presence, try, try! 90 | Style/SafeNavigation: 91 | Exclude: 92 | - 'lib/puppet/provider/sysctl/augeas.rb' 93 | 94 | # Offense count: 2 95 | # This cop supports unsafe autocorrection (--autocorrect-all). 96 | # Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments. 97 | # AllowedMethods: define_method 98 | Style/SymbolProc: 99 | Exclude: 100 | - 'lib/puppet/type/sysctl.rb' 101 | -------------------------------------------------------------------------------- /lib/puppet/type/sysctl.rb: -------------------------------------------------------------------------------- 1 | # Manages entries in /etc/sysctl.conf 2 | # 3 | # Copyright (c) 2012 Dominic Cleal 4 | # Licensed under the Apache License, Version 2.0 5 | 6 | Puppet::Type.newtype(:sysctl) do 7 | @doc = 'Manages entries in /etc/sysctl.conf.' 8 | 9 | ensurable 10 | 11 | newparam(:name) do 12 | desc 'The name of the setting, e.g. net.ipv4.ip_forward' 13 | isnamevar 14 | end 15 | 16 | module SysctlValueSync 17 | def insync?(is) 18 | _is_insync = true 19 | 20 | if provider.valid_resource?(resource[:name]) 21 | if resource[:apply] == :true 22 | @live_value = provider.live_value 23 | 24 | _is_insync = equal(should, @live_value) 25 | end 26 | 27 | _is_insync = equal(should, is) if _is_insync && (resource[:persist] == :true) 28 | else 29 | # We won't get here unless exists? has been short circuited so we can 30 | # rely on that to raise an approprite error. 31 | debug("augeasproviders_sysctl: skipping insync? due to invalid resource `#{resource[:name]}`") 32 | end 33 | 34 | _is_insync 35 | end 36 | 37 | def change_to_s(current, new) 38 | return "changed configuration value from '#{current}' to '#{new}'" unless resource[:apply] == :true 39 | 40 | if equal(current, new) 41 | "changed live value from '#{@live_value}' to '#{new}'" 42 | elsif equal(@live_value, new) 43 | "changed configuration value from '#{current}' to '#{new}'" 44 | else 45 | return "changed configuration value from '#{current}' to '#{new}' and live value from '#{@live_value}' to '#{new}'" if resource[:persist] == :true 46 | 47 | "changed live value from '#{@live_value}' to '#{new}'" 48 | 49 | end 50 | end 51 | 52 | def equal(a, b) 53 | a && b && (a.gsub(%r{\s+}, ' ') == b.gsub(%r{\s+}, ' ')) 54 | end 55 | end 56 | 57 | newproperty(:val) do 58 | desc "An alias for 'value'. Maintains interface compatibility with the traditional ParsedFile sysctl provider. If both are set, 'value' will take precedence over 'val'." 59 | 60 | munge do |val| 61 | val.to_s 62 | end 63 | 64 | include SysctlValueSync 65 | end 66 | 67 | newproperty(:value) do 68 | desc 'Value to change the setting to. Settings with multiple values (such as net.ipv4.tcp_mem) are represented as a single whitespace separated string.' 69 | 70 | munge do |val| 71 | val.to_s 72 | end 73 | 74 | include SysctlValueSync 75 | end 76 | 77 | newparam(:target) do 78 | desc "The file in which to store the settings, defaults to 79 | `/etc/sysctl.conf`." 80 | end 81 | 82 | newproperty(:comment) do 83 | desc 'Text to be stored in a comment immediately above the entry. It will be automatically prepended with the name of the setting in order for the provider to know whether it controls the comment or not.' 84 | 85 | def insync?(is) 86 | return true unless resource[:persist] == :true 87 | 88 | super 89 | end 90 | end 91 | 92 | newparam(:apply, boolean: true) do 93 | desc 'Whether to apply the value using the sysctl command.' 94 | newvalues(:true, :false) 95 | defaultto(:true) 96 | end 97 | 98 | newparam(:persist, boolean: true) do 99 | desc 'Persist the value in the on-disk file ($target).' 100 | newvalues(:true, :false) 101 | defaultto(:true) 102 | end 103 | 104 | newparam(:silent, boolean: true) do 105 | desc 'If set, do not report an error if the system key does not exist. This is useful for systems that may need to load a kernel module prior to the sysctl values existing.' 106 | newvalues(:true, :false) 107 | defaultto(:false) 108 | end 109 | 110 | autorequire(:file) do 111 | self[:target] 112 | end 113 | end 114 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/workflows/CI/badge.svg)](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/actions?query=workflow%3ACI) 2 | [![Release](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/actions/workflows/release.yml/badge.svg)](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/actions/workflows/release.yml) 3 | [![Code Coverage](https://coveralls.io/repos/github/voxpupuli/puppet-augeasproviders_sysctl/badge.svg?branch=master)](https://coveralls.io/github/voxpupuli/puppet-augeasproviders_sysctl) 4 | [![Puppet Forge](https://img.shields.io/puppetforge/v/puppet/augeasproviders_sysctl.svg)](https://forge.puppetlabs.com/puppet/augeasproviders_sysctl) 5 | [![Puppet Forge - downloads](https://img.shields.io/puppetforge/dt/puppet/augeasproviders_sysctl.svg)](https://forge.puppetlabs.com/puppet/augeasproviders_sysctl) 6 | [![Puppet Forge - endorsement](https://img.shields.io/puppetforge/e/puppet/augeasproviders_sysctl.svg)](https://forge.puppetlabs.com/puppet/augeasproviders_sysctl) 7 | [![Puppet Forge - scores](https://img.shields.io/puppetforge/f/puppet/augeasproviders_sysctl.svg)](https://forge.puppetlabs.com/puppet/augeasproviders_sysctl) 8 | [![puppetmodule.info docs](http://www.puppetmodule.info/images/badge.png)](http://www.puppetmodule.info/m/puppet-augeasproviders_sysctl) 9 | [![Apache-2 License](https://img.shields.io/github/license/voxpupuli/puppet-augeasproviders_sysctl.svg)](LICENSE) 10 | 11 | 12 | # sysctl: type/provider for sysctl for Puppet 13 | 14 | This module provides a new type/provider for Puppet to read and modify sysctl 15 | config files using the Augeas configuration library. 16 | 17 | The advantage of using Augeas over the default Puppet `parsedfile` 18 | implementations is that Augeas will go to great lengths to preserve file 19 | formatting and comments, while also failing safely when needed. 20 | 21 | This provider will hide *all* of the Augeas commands etc., you don't need to 22 | know anything about Augeas to make use of it. 23 | 24 | ## Requirements 25 | 26 | Ensure both Augeas and ruby-augeas 0.3.0+ bindings are installed and working as 27 | normal. 28 | 29 | See [Puppet/Augeas pre-requisites](http://docs.puppetlabs.com/guides/augeas.html#pre-requisites). 30 | 31 | ## Documentation and examples 32 | 33 | Type documentation can be generated with `puppet doc -r type` or viewed on the 34 | [Puppet Forge page](http://forge.puppetlabs.com/puppet/augeasproviders_sysctl). 35 | 36 | 37 | ### manage simple entry 38 | 39 | sysctl { "net.ipv4.ip_forward": 40 | ensure => present, 41 | value => "1", 42 | } 43 | 44 | ### manage entry with comment 45 | 46 | sysctl { "net.ipv4.ip_forward": 47 | ensure => present, 48 | value => "1", 49 | comment => "test", 50 | } 51 | 52 | ### delete entry 53 | 54 | sysctl { "kernel.sysrq": 55 | ensure => absent, 56 | } 57 | 58 | ### remove comment from entry 59 | 60 | sysctl { "kernel.sysrq": 61 | ensure => present, 62 | comment => "", 63 | } 64 | 65 | ### manage entry in another sysctl.conf location 66 | 67 | sysctl { "net.ipv4.ip_forward": 68 | ensure => present, 69 | value => "1", 70 | target => "/etc/sysctl.d/forwarding.conf", 71 | } 72 | 73 | ### do not update value with the `sysctl` command 74 | 75 | sysctl { "net.ipv4.ip_forward": 76 | ensure => present, 77 | value => "1", 78 | apply => false, 79 | } 80 | 81 | ### only update the value with the `sysctl` command, do not persist to disk 82 | 83 | sysctl { "net.ipv4.ip_forward": 84 | ensure => present, 85 | value => "1", 86 | persist => false, 87 | } 88 | 89 | ### ignore the application of a yet to be activated sysctl value 90 | 91 | sysctl { "net.ipv6.conf.all.autoconf": 92 | ensure => present, 93 | value => "1", 94 | silent => true 95 | } 96 | 97 | ## Issues 98 | 99 | Please file any issues or suggestions [on GitHub](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/issues). 100 | 101 | ## Transfer Notice 102 | 103 | This plugin was originally authored by [hercules-team](http://augeasproviders.com). 104 | The maintainer preferred that Puppet Community take ownership of the module for future improvement and maintenance. 105 | Existing pull requests and issues were transferred over, please fork and continue to contribute here instead of hercules-team. 106 | 107 | Previously: https://github.com/hercules-team/augeasproviders_sysctl 108 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | Each new release typically also includes the latest modulesync defaults. 5 | These should not affect the functionality of the module. 6 | 7 | ## [v3.3.0](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/tree/v3.3.0) (2024-12-09) 8 | 9 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/compare/v3.2.0...v3.3.0) 10 | 11 | **Implemented enhancements:** 12 | 13 | - Support EL9 [\#99](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/pull/99) ([treydock](https://github.com/treydock)) 14 | - add support for Ubuntu 24.04 [\#98](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/pull/98) ([techsk8](https://github.com/techsk8)) 15 | 16 | ## [v3.2.0](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/tree/v3.2.0) (2023-10-30) 17 | 18 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/compare/v3.1.0...v3.2.0) 19 | 20 | **Implemented enhancements:** 21 | 22 | - Add Rocky/AlmaLinux support [\#85](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/pull/85) ([bastelfreak](https://github.com/bastelfreak)) 23 | - Add Debian 12 support [\#83](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/pull/83) ([bastelfreak](https://github.com/bastelfreak)) 24 | 25 | ## [v3.1.0](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/tree/v3.1.0) (2023-06-22) 26 | 27 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/compare/v3.0.0...v3.1.0) 28 | 29 | **Implemented enhancements:** 30 | 31 | - Add puppet 8 support [\#77](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/pull/77) ([bastelfreak](https://github.com/bastelfreak)) 32 | 33 | ## [v3.0.0](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/tree/v3.0.0) (2023-04-28) 34 | 35 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/compare/2.6.2...v3.0.0) 36 | 37 | **Breaking changes:** 38 | 39 | - Drop Puppet 6 support [\#73](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/pull/73) ([bastelfreak](https://github.com/bastelfreak)) 40 | 41 | **Closed issues:** 42 | 43 | - Dependency on puppet-augeasproviders\_core [\#70](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/issues/70) 44 | - Release 2.6.2 missing on Forge [\#64](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/issues/64) 45 | 46 | **Merged pull requests:** 47 | 48 | - Final transfer fixes [\#72](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/pull/72) ([h-haaks](https://github.com/h-haaks)) 49 | - Fix broken Apache-2 license [\#71](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/pull/71) ([bastelfreak](https://github.com/bastelfreak)) 50 | - Update git:// github.com submodule URL to use https:// [\#67](https://github.com/voxpupuli/puppet-augeasproviders_sysctl/pull/67) ([jamespwilliams](https://github.com/jamespwilliams)) 51 | 52 | ## 2.6.2 53 | 54 | - Add support for augeasproviders_core 3 55 | - Add support for puppet 7 56 | - Fix OpenBSD support 57 | - Fix handling of entries with the 'target' specified 58 | - Fix bug in sysctl arguments on FreeBSD 59 | 60 | ## 2.6.1 61 | 62 | - Optimize provider resource creation during prefetch to reduce system load 63 | - Fix support for OpenBSD 64 | 65 | ## 2.6.0 66 | 67 | - FreeBSD: skip read-only MIB data (GH #48) 68 | 69 | ## 2.5.1 70 | 71 | - Force data read from 'sysctl -a' into ASCSII (GH #46) 72 | 73 | ## 2.5.0 74 | 75 | - Add support for: 76 | - Debian 10 77 | - EL 8 78 | 79 | ## 2.4.0 80 | 81 | - Add Archlinux support (GH #38) 82 | - Use : as separator on FreeBSD (fix #24) (GH #30) 83 | - Do not manage comment when persist is false (fix #29) (GH #31) 84 | 85 | ## 2.3.1 86 | 87 | - Fix puppet requirement to < 7.0.0 88 | 89 | ## 2.3.0 90 | 91 | - Add support for Puppet 6 92 | - Deprecate support for Puppet < 5 93 | - Update supported OSes in metadata.json 94 | 95 | ## 2.2.1 96 | - Added support for Puppet 5 and OEL 97 | 98 | ## 2.2.0 99 | - Removed Travis tests for Puppet < 4.7 since that is the most common LTS 100 | release and Puppet 3 is well out of support 101 | - Added OpenBSD and FreeBSD to the compatibility list 102 | - Added a :persist option for enabling saving to the /etc/sysctl.conf file 103 | - Added the capability to update either the live value *or* the disk value 104 | independently 105 | - Now use prefetching to get the sysctl values 106 | - Updated self.instances to obtain information about *all* sysctl values which 107 | provides a more accurate representation of the system when using `puppet 108 | resource` 109 | - Updated all tests 110 | 111 | ## 2.1.0 112 | - Added a :silent option for deliberately ignoring failures when applying the 113 | live sysctl setting. 114 | - Added acceptance tests 115 | 116 | ## 2.0.2 117 | 118 | - Improve Gemfile 119 | - Do not version Gemfile.lock 120 | - Add badges to README 121 | - Munge values to strings 122 | - Add specs for the sysctl type 123 | 124 | ## 2.0.1 125 | 126 | - Convert specs to rspec3 syntax 127 | - Fix metadata.json 128 | 129 | ## 2.0.0 130 | 131 | - First release of split module. 132 | 133 | 134 | \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* 135 | -------------------------------------------------------------------------------- /spec/acceptance/sysctl_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper_acceptance' 2 | 3 | test_name 'Augeasproviders Sysctl' 4 | 5 | describe 'Sysctl Tests' do 6 | hosts.each do |host| 7 | context "on #{host}" do 8 | context 'file based updates' do 9 | let(:manifest) do 10 | <<-EOM 11 | sysctl { 'fs.nr_open': 12 | value => '100000', 13 | apply => false 14 | } 15 | EOM 16 | end 17 | 18 | # Using puppet_apply as a helper 19 | it 'works with no errors' do 20 | apply_manifest_on(host, manifest, catch_failures: true) 21 | end 22 | 23 | it 'is idempotent' do 24 | apply_manifest_on(host, manifest, { catch_changes: true }) 25 | end 26 | 27 | it 'has applied successfuly in the sysctl config but not live' do 28 | result = on(host, 'sysctl -n fs.nr_open').stdout.strip 29 | expect(result).not_to eql('100000') 30 | 31 | on(host, 'sysctl -p', accept_all_exit_codes: true) 32 | result = on(host, 'sysctl -n fs.nr_open').stdout.strip 33 | expect(result).to eql('100000') 34 | end 35 | end 36 | 37 | context 'full updates' do 38 | let(:manifest) do 39 | <<-EOM 40 | sysctl { 'fs.nr_open': 41 | value => '100001' 42 | } 43 | EOM 44 | end 45 | 46 | # Using puppet_apply as a helper 47 | it 'works with no errors' do 48 | apply_manifest_on(host, manifest, catch_failures: true) 49 | end 50 | 51 | it 'is idempotent' do 52 | apply_manifest_on(host, manifest, { catch_changes: true }) 53 | end 54 | 55 | it 'applies successfuly in the config and live' do 56 | result = on(host, 'sysctl -n fs.nr_open').stdout.strip 57 | expect(result).to eql('100001') 58 | end 59 | 60 | context 'when given an invalid key' do 61 | let(:manifest) do 62 | <<-EOM 63 | sysctl { 'fs.this_cannot_exist': 64 | value => 'I like bread' 65 | } 66 | EOM 67 | end 68 | 69 | it 'fails to apply to the system' do 70 | apply_manifest_on(host, manifest, expect_failures: true) 71 | end 72 | end 73 | 74 | context 'when silent' do 75 | let(:manifest) do 76 | <<-EOM 77 | sysctl { 'fs.nr_open': 78 | value => '100002', 79 | silent => true 80 | } 81 | EOM 82 | end 83 | 84 | # Using puppet_apply as a helper 85 | it 'works with no errors' do 86 | apply_manifest_on(host, manifest, catch_failures: true) 87 | end 88 | 89 | it 'is idempotent' do 90 | apply_manifest_on(host, manifest, { catch_changes: true }) 91 | end 92 | end 93 | 94 | context 'when silent and given a key that does not exist' do 95 | let(:manifest) do 96 | <<-EOM 97 | sysctl { 'fs.this_cannot_exist': 98 | value => 'I like bread', 99 | silent => true 100 | } 101 | EOM 102 | end 103 | 104 | # Using puppet_apply as a helper 105 | it 'works with no errors' do 106 | apply_manifest_on(host, manifest, catch_failures: true) 107 | end 108 | 109 | it 'is idempotent' do 110 | apply_manifest_on(host, manifest, { catch_changes: true }) 111 | end 112 | end 113 | 114 | context 'when only applying to the running system' do 115 | let(:manifest) do 116 | <<-EOM 117 | sysctl { 'kernel.pty.max': 118 | value => 4097, 119 | apply => true, 120 | persist => false 121 | } 122 | EOM 123 | end 124 | 125 | # Using puppet_apply as a helper 126 | it 'works with no errors' do 127 | apply_manifest_on(host, manifest, catch_failures: true) 128 | end 129 | 130 | it 'is idempotent' do 131 | apply_manifest_on(host, manifest, { catch_changes: true }) 132 | end 133 | 134 | it 'is not in /etc/sysctl.conf' do 135 | expect(file_contents_on(host, '/etc/sysctl.conf')).not_to match(%r{kernel\.pty\.max}) 136 | end 137 | end 138 | 139 | context 'when only applying to the filesystem' do 140 | let(:manifest) do 141 | <<-EOM 142 | sysctl { 'kernel.pty.max': 143 | comment => 'just a test', 144 | value => 4098, 145 | apply => false, 146 | persist => true 147 | } 148 | EOM 149 | end 150 | 151 | # Using puppet_apply as a helper 152 | it 'works with no errors' do 153 | apply_manifest_on(host, manifest, catch_failures: true) 154 | end 155 | 156 | it 'is idempotent' do 157 | apply_manifest_on(host, manifest, { catch_changes: true }) 158 | end 159 | 160 | it 'is in /etc/sysctl.conf' do 161 | expect(file_contents_on(host, '/etc/sysctl.conf')).to match(%r{kernel\.pty\.max = 4098}) 162 | end 163 | 164 | it 'is not changed on the running system' do 165 | result = on(host, 'sysctl -n kernel.pty.max').stdout.strip 166 | expect(result).to eql('4097') 167 | end 168 | end 169 | 170 | context 'when deleting an entry' do 171 | let(:manifest) do 172 | <<-EOM 173 | sysctl { 'kernel.pty.max': 174 | ensure => absent 175 | } 176 | EOM 177 | end 178 | 179 | # Using puppet_apply as a helper 180 | it 'works with no errors' do 181 | apply_manifest_on(host, manifest, catch_failures: true) 182 | end 183 | 184 | it 'is idempotent' do 185 | apply_manifest_on(host, manifest, { catch_changes: true }) 186 | end 187 | 188 | it 'is not in /etc/sysctl.conf' do 189 | expect(file_contents_on(host, '/etc/sysctl.conf')).not_to match(%r{kernel\.pty\.max}) 190 | end 191 | 192 | it 'is not changed on the running system' do 193 | result = on(host, 'sysctl -n kernel.pty.max').stdout.strip 194 | expect(result).to eql('4097') 195 | end 196 | end 197 | 198 | context 'when using a target file' do 199 | let(:manifest) do 200 | <<-EOM 201 | if $facts['os']['family'] == 'RedHat' and versioncmp($facts['os']['release']['major'], '9') >= 0 { 202 | package { 'systemd-udev': 203 | ensure => 'installed', 204 | } 205 | Package['systemd-udev'] -> Sysctl <| |> 206 | } 207 | sysctl { 'fs.nr_open': 208 | value => '100001', 209 | target => '/etc/sysctl.d/20-fs.conf' 210 | } 211 | 212 | sysctl { 'fs.inotify.max_user_watches': 213 | value => '8193', 214 | target => '/etc/sysctl.d/20-fs.conf' 215 | } 216 | EOM 217 | end 218 | 219 | it 'works with no errors' do 220 | apply_manifest_on(host, manifest, catch_failures: true) 221 | end 222 | 223 | it 'is idempotent' do 224 | apply_manifest_on(host, manifest, { catch_changes: true }) 225 | end 226 | 227 | it 'has correct file contents' do 228 | expect(file_contents_on(host, '/etc/sysctl.conf')).to match(%r{fs\.nr_open = 100002}) 229 | expect(file_contents_on(host, '/etc/sysctl.conf')).not_to match(%r{fs\.inotify\.max_user_watches}) 230 | expect(file_contents_on(host, '/etc/sysctl.d/20-fs.conf')).to match(%r{fs\.nr_open = 100001}) 231 | expect(file_contents_on(host, '/etc/sysctl.d/20-fs.conf')).to match(%r{fs\.inotify\.max_user_watches = 8193}) 232 | end 233 | 234 | context 'when deleting an entry' do 235 | let(:manifest) do 236 | <<-EOM 237 | sysctl { 'fs.inotify.max_user_watches': 238 | ensure => absent, 239 | target => '/etc/sysctl.d/20-fs.conf' 240 | } 241 | EOM 242 | end 243 | 244 | it 'works with no errors' do 245 | apply_manifest_on(host, manifest, catch_failures: true) 246 | end 247 | 248 | it 'is idempotent' do 249 | apply_manifest_on(host, manifest, { catch_changes: true }) 250 | end 251 | 252 | it 'has been removed from the system' do 253 | expect(file_contents_on(host, '/etc/sysctl.d/20-fs.conf')).not_to match(%r{fs\.inotify\.max_user_watches}) 254 | end 255 | end 256 | end 257 | end 258 | end 259 | end 260 | end 261 | -------------------------------------------------------------------------------- /lib/puppet/provider/sysctl/augeas.rb: -------------------------------------------------------------------------------- 1 | # Alternative Augeas-based provider for sysctl type 2 | # 3 | # Copyright (c) 2012 Dominic Cleal 4 | # Licensed under the Apache License, Version 2.0 5 | 6 | raise('Missing augeasproviders_core dependency') if Puppet::Type.type(:augeasprovider).nil? 7 | 8 | Puppet::Type.type(:sysctl).provide(:augeas, parent: Puppet::Type.type(:augeasprovider).provider(:default)) do 9 | desc 'Uses Augeas API to update sysctl settings' 10 | 11 | default_file { '/etc/sysctl.conf' } 12 | 13 | lens { 'Sysctl.lns' } 14 | 15 | optional_commands sysctl: 'sysctl' 16 | 17 | resource_path do |resource| 18 | "$target/#{resource[:name]}" 19 | end 20 | 21 | def self.sysctl_set(key, value, silent = false) 22 | if Facter.value(:kernel) == :openbsd 23 | sysctl("#{key}=#{value}") 24 | else 25 | sysctl('-w', %(#{key}=#{value})) 26 | end 27 | rescue Puppet::ExecutionFailure => e 28 | raise e unless silent 29 | 30 | debug("augeasprovider_sysctl ignoring failed attempt to set #{key} due to :silent mode") 31 | end 32 | 33 | def self.sysctl_get(key) 34 | sysctl('-n', key).chomp 35 | end 36 | 37 | confine feature: :augeas 38 | 39 | def self.collect_augeas_resources(res, entries, target = '/etc/sysctl.conf', resources) 40 | resources ||= [] 41 | 42 | augopen(res) do |aug| 43 | entries.each do |entry| 44 | next if resources.find { |x| x[:name] == entry } 45 | 46 | value = aug.get("$target/#{entry}") 47 | 48 | next unless value 49 | 50 | resource = { 51 | name: entry, 52 | ensure: :present, 53 | persist: :true, 54 | value: value, 55 | target: target 56 | } 57 | 58 | # Only match comments immediately before the entry and prefixed with 59 | # the sysctl name 60 | cmtnode = aug.match("$target/#comment[following-sibling::*[1][self::#{entry}]]") 61 | unless cmtnode.empty? 62 | comment = aug.get(cmtnode[0]) 63 | resource[:comment] = comment.sub(%r{^#{resource[:name]}:\s*}, '') if comment.match(%r{#{resource[:name]}:}) 64 | end 65 | 66 | resources << resource 67 | end 68 | end 69 | 70 | resources 71 | end 72 | 73 | def self.instances(reference_resources = nil) 74 | resources = [] 75 | sysctl_output = '' 76 | 77 | if reference_resources 78 | reference_resource_titles = reference_resources.map { |_ref_name, ref_obj| ref_obj.title } 79 | resource_dup = reference_resources.first.last.dup 80 | 81 | collect_augeas_resources( 82 | resource_dup, 83 | reference_resource_titles, 84 | resource_dup[:target], 85 | resources 86 | ) 87 | 88 | sysctl_args = if Facter.value(:kernel) == 'OpenBSD' 89 | # OpenBSD doesn't support -e 90 | [''] 91 | elsif Facter.value(:kernel) == 'FreeBSD' 92 | ['-ieW'] 93 | else 94 | ['-e'] 95 | end 96 | 97 | # Split this into chunks so that we don't exceed command line limits 98 | reference_resource_titles.each_slice(30) do |resource_title_slice| 99 | sysctl_args << resource_title_slice 100 | 101 | sysctl_output += sysctl(sysctl_args.flatten) 102 | end 103 | else 104 | targets = ['/etc/sysctl.d/*.conf', '/etc/sysctl.conf'] 105 | targets = [target] if target 106 | 107 | Dir.glob(targets).reverse.each do |config_file| 108 | tmp_res = Puppet::Resource.new('sysctl', 'ignored') 109 | tmp_res[:target] = config_file 110 | 111 | entries = [] 112 | augopen(tmp_res) do |aug| 113 | entries = aug.match('$target/*'). 114 | delete_if { |x| x.match?(%r{#comment}) }. 115 | map { |x| x.split('/').last } 116 | end 117 | 118 | collect_augeas_resources( 119 | tmp_res, 120 | entries, 121 | config_file, 122 | resources 123 | ) 124 | end 125 | 126 | sysctl_args = ['-a'] 127 | 128 | sysctl_args = ['-aeW'] if Facter.value(:kernel) == 'FreeBSD' 129 | 130 | sysctl_output = sysctl(sysctl_args) 131 | end 132 | 133 | sep = '=' 134 | sysctl_output.each_line do |line| 135 | line = line.force_encoding('US-ASCII').scrub('') 136 | value = line.split(sep) 137 | 138 | key = value.shift.strip 139 | 140 | value = value.join(sep).strip 141 | 142 | existing_index = resources.index { |x| x[:name] == key } 143 | 144 | if existing_index 145 | resources[existing_index][:apply] = :true 146 | else 147 | newres = { 148 | name: key, 149 | ensure: :present, 150 | value: value, 151 | apply: :true, 152 | persist: :false 153 | } 154 | 155 | newres[:target] = target if target 156 | 157 | resources << newres 158 | end 159 | end 160 | 161 | resources.map { |x| x = new(x) } 162 | end 163 | 164 | def self.prefetch(resources) 165 | # We need to pass a reference resource so that the proper target is in 166 | # scope. 167 | instances(resources).each do |prov| 168 | if resource = resources[prov.name] 169 | resource.provider = prov 170 | end 171 | end 172 | end 173 | 174 | def create 175 | return unless resource[:persist] == :true 176 | raise Puppet::Error, "Error: `#{resource[:name]}` is not a valid sysctl key" if !valid_resource?(resource[:name]) && (resource[:silent] == :false) 177 | 178 | # the value to pass to augeas can come either from the 'value' or the 179 | # 'val' type parameter. 180 | value = resource[:value] || resource[:val] 181 | 182 | augopen! do |aug| 183 | # Prefer to create the node next to a commented out entry 184 | commented = aug.match("$target/#comment[.=~regexp('#{resource[:name]}([^a-z.].*)?')]") 185 | aug.insert(commented.first, resource[:name], false) unless commented.empty? 186 | aug.set(resource_path, value) 187 | setvars(aug) 188 | end 189 | end 190 | 191 | def valid_resource?(name) 192 | @property_hash.is_a?(Hash) && @property_hash[:name] == name 193 | end 194 | 195 | def exists? 196 | # If in silent mode, short circuit the process on an invalid key 197 | # 198 | # This only matters when creating entries since invalid missing entries 199 | # might be used to clean up /etc/sysctl.conf 200 | if resource[:ensure] != :absent && !valid_resource?(resource[:name]) 201 | raise Puppet::Error, "Error: `#{resource[:name]}` is not a valid sysctl key" unless resource[:silent] == :true 202 | 203 | debug("augeasproviders_sysctl: `#{resource[:name]}` is not a valid sysctl key") 204 | return true 205 | 206 | end 207 | 208 | if @property_hash[:ensure] == :present 209 | # Short circuit this if there's nothing to do 210 | return false if (resource[:ensure] == :absent) && (@property_hash[:persist] == :false) 211 | 212 | true 213 | 214 | else 215 | super 216 | end 217 | end 218 | 219 | define_aug_method!(:destroy) do |aug, resource| 220 | aug.rm("$target/#comment[following-sibling::*[1][self::#{resource[:name]}]][. =~ regexp('#{resource[:name]}:.*')]") 221 | aug.rm('$resource') 222 | end 223 | 224 | def live_value 225 | return self.class.sysctl_get(resource[:name]) unless resource[:silent] == :true 226 | 227 | debug("augeasproviders_sysctl not setting live value for #{resource[:name]} due to :silent mode") 228 | return resource[:value] if resource[:value] 229 | 230 | resource[:val] 231 | end 232 | 233 | attr_aug_accessor(:value, label: :resource) 234 | 235 | alias_method :val, :value 236 | alias_method :val=, :value= 237 | 238 | define_aug_method(:comment) do |aug, resource| 239 | comment = aug.get("$target/#comment[following-sibling::*[1][self::#{resource[:name]}]][. =~ regexp('#{resource[:name]}:.*')]") 240 | comment.sub!(%r{^#{resource[:name]}:\s*}, '') if comment 241 | comment || '' 242 | end 243 | 244 | define_aug_method!(:comment=) do |aug, resource, value| 245 | cmtnode = "$target/#comment[following-sibling::*[1][self::#{resource[:name]}]][. =~ regexp('#{resource[:name]}:.*')]" 246 | if value.empty? 247 | aug.rm(cmtnode) 248 | else 249 | aug.insert('$resource', '#comment', true) if aug.match(cmtnode).empty? 250 | aug.set("$target/#comment[following-sibling::*[1][self::#{resource[:name]}]]", 251 | "#{resource[:name]}: #{resource[:comment]}") 252 | end 253 | end 254 | 255 | def flush 256 | if resource[:ensure] == :absent 257 | super 258 | else 259 | if resource[:apply] == :true 260 | value = resource[:value] || resource[:val] 261 | if value 262 | silent = (resource[:silent] == :true) 263 | self.class.sysctl_set(resource[:name], value, silent) 264 | end 265 | end 266 | 267 | # Ensures that we only save to disk when we're supposed to 268 | if resource[:persist] == :true 269 | # Create the entry on disk if it's not already there 270 | create if @property_hash[:persist] == :false 271 | 272 | super 273 | end 274 | end 275 | end 276 | end 277 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /spec/unit/puppet/provider/sysctl/augeas_spec.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rspec 2 | 3 | require 'spec_helper' 4 | 5 | provider_class = Puppet::Type.type(:sysctl).provider(:augeas) 6 | 7 | describe provider_class do 8 | before do 9 | allow(FileTest).to receive(:exist?).and_return(false) 10 | allow(FileTest).to receive(:exist?).with('/etc/sysctl.conf').and_return(true) 11 | 12 | # TODO: Is there a better way? 13 | # provider_class.instance_variable_set(:@resource_cache, nil) 14 | 15 | # This needs to be a list of all sysctls used in the tests so that prefetch 16 | # works and the provider doesn't fail on an invalid key. 17 | allow(provider_class).to receive(:sysctl).with(['-a']).and_return([ 18 | 'net.ipv4.ip_forward = 1', 19 | 'net.bridge.bridge-nf-call-iptables = 0', 20 | 'kernel.sem = 100 13000 11 1200', 21 | 'kernel.sysrq = 0', 22 | '' 23 | ].join("\n")) 24 | end 25 | 26 | before(:all) { @tmpdir = Dir.mktmpdir } 27 | after(:all) { FileUtils.remove_entry_secure @tmpdir } 28 | 29 | context 'with no existing file' do 30 | let(:target) { File.join(@tmpdir, 'new_file') } 31 | 32 | before do 33 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=0') 34 | expect(provider_class).to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=1') 35 | expect(provider_class).to receive(:sysctl).with('-n', 'net.ipv4.ip_forward').at_least(:once).and_return('1') 36 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=1') 37 | end 38 | 39 | it 'creates simple new entry' do 40 | apply!(Puppet::Type.type(:sysctl).new( 41 | name: 'net.ipv4.ip_forward', 42 | value: '1', 43 | target: target, 44 | provider: 'augeas' 45 | )) 46 | 47 | augparse(target, 'Sysctl.lns', ' 48 | { "net.ipv4.ip_forward" = "1" } 49 | ') 50 | end 51 | end 52 | 53 | context 'with empty file' do 54 | let(:tmptarget) { aug_fixture('empty') } 55 | let(:target) { tmptarget.path } 56 | 57 | before do 58 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=0') 59 | expect(provider_class).to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=1') 60 | expect(provider_class).to receive(:sysctl).with('-n', 'net.ipv4.ip_forward').at_least(:once).and_return('1') 61 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=1') 62 | end 63 | 64 | it 'creates simple new entry' do 65 | apply!(Puppet::Type.type(:sysctl).new( 66 | name: 'net.ipv4.ip_forward', 67 | value: '1', 68 | target: target, 69 | provider: 'augeas' 70 | )) 71 | 72 | augparse(target, 'Sysctl.lns', ' 73 | { "net.ipv4.ip_forward" = "1" } 74 | ') 75 | end 76 | 77 | it 'creates an entry using the val parameter instead of value' do 78 | apply!(Puppet::Type.type(:sysctl).new( 79 | name: 'net.ipv4.ip_forward', 80 | val: '1', 81 | target: target, 82 | provider: 'augeas' 83 | )) 84 | 85 | augparse(target, 'Sysctl.lns', ' 86 | { "net.ipv4.ip_forward" = "1" } 87 | ') 88 | end 89 | 90 | it 'creates new entry with comment' do 91 | apply!(Puppet::Type.type(:sysctl).new( 92 | name: 'net.ipv4.ip_forward', 93 | value: '1', 94 | comment: 'test', 95 | target: target, 96 | provider: 'augeas' 97 | )) 98 | 99 | augparse(target, 'Sysctl.lns', ' 100 | { "#comment" = "net.ipv4.ip_forward: test" } 101 | { "net.ipv4.ip_forward" = "1" } 102 | ') 103 | end 104 | end 105 | 106 | context 'with full file' do 107 | let(:tmptarget) { aug_fixture('full') } 108 | let(:target) { tmptarget.path } 109 | 110 | it 'lists instances' do 111 | allow(provider_class).to receive(:target).and_return(target) 112 | 113 | inst = provider_class.instances.map do |p| 114 | { 115 | name: p.get(:name), 116 | ensure: p.get(:ensure), 117 | value: p.get(:value), 118 | comment: p.get(:comment), 119 | } 120 | end 121 | 122 | expect(inst.size).to eq(9) 123 | expect(inst[0]).to eq({ name: 'net.ipv4.ip_forward', ensure: :present, value: '0', comment: :absent }) 124 | expect(inst[1]).to eq({ name: 'net.ipv4.conf.default.rp_filter', ensure: :present, value: '1', comment: :absent }) 125 | expect(inst[2]).to eq({ name: 'net.ipv4.conf.default.accept_source_route', ensure: :present, value: '0', comment: 'Do not accept source routing' }) 126 | expect(inst[3]).to eq({ name: 'kernel.sysrq', ensure: :present, value: '0', comment: 'controls the System Request debugging functionality of the kernel' }) 127 | end 128 | 129 | it 'creates new entry next to commented out entry' do 130 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.bridge.bridge-nf-call-iptables']).and_return('net.bridge.bridge-nf-call-iptables=0') 131 | expect(provider_class).to receive(:sysctl).with('-w', 'net.bridge.bridge-nf-call-iptables=1') 132 | expect(provider_class).to receive(:sysctl).with('-n', 'net.bridge.bridge-nf-call-iptables').at_least(:once).and_return('1') 133 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.bridge.bridge-nf-call-iptables']).and_return('net.bridge.bridge-nf-call-iptables=1') 134 | 135 | apply!(Puppet::Type.type(:sysctl).new( 136 | name: 'net.bridge.bridge-nf-call-iptables', 137 | value: '1', 138 | target: target, 139 | provider: 'augeas' 140 | )) 141 | 142 | augparse_filter(target, 'Sysctl.lns', '*[preceding-sibling::#comment[.="Disable netfilter on bridges."]]', ' 143 | { "net.bridge.bridge-nf-call-ip6tables" = "0" } 144 | { "#comment" = "net.bridge.bridge-nf-call-iptables = 0" } 145 | { "net.bridge.bridge-nf-call-iptables" = "1" } 146 | { "net.bridge.bridge-nf-call-arptables" = "0" } 147 | ') 148 | end 149 | 150 | it 'equates multi-part values with tabs in' do 151 | expect(provider_class).to receive(:sysctl).with(['-e', 'kernel.sem']).and_return("kernel.sem=123\t123\t123\t123") 152 | expect(provider_class).to receive(:sysctl).with('-n', 'kernel.sem').at_least(:once).and_return("150\t12000\t12\t1000") 153 | expect(provider_class).to receive(:sysctl).with('-w', 'kernel.sem=150 12000 12 1000') 154 | expect(provider_class).to receive(:sysctl).with(['-e', 'kernel.sem']).and_return("kernel.sem=150\t12000\t12\t1000") 155 | 156 | apply!(Puppet::Type.type(:sysctl).new( 157 | name: 'kernel.sem', 158 | value: '150 12000 12 1000', 159 | apply: true, 160 | target: target, 161 | provider: 'augeas' 162 | )) 163 | 164 | augparse_filter(target, 'Sysctl.lns', 'kernel.sem', ' 165 | { "kernel.sem" = "150 12000 12 1000" } 166 | ') 167 | end 168 | 169 | # Validated that it *does* delete the entries but somethign about prefetch 170 | # isn't playing well with the way the tests are loaded and, unfortunately, 171 | # I can't short circuit it. 172 | xit 'should delete entries' do 173 | apply!(Puppet::Type.type(:sysctl).new( 174 | name: 'kernel.sysrq', 175 | ensure: 'absent', 176 | target: target, 177 | provider: 'augeas' 178 | )) 179 | 180 | aug_open(target, 'Sysctl.lns') do |aug| 181 | expect(aug.match('kernel.sysrq')).to eq([]) 182 | expect(aug.match("#comment[. =~ regexp('kernel.sysrq:.*')]")).to eq([]) 183 | end 184 | end 185 | 186 | context 'when system and config values are set to different values' do 187 | it 'updates value with augeas and sysctl' do 188 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=3') 189 | expect(provider_class).to receive(:sysctl).with('-n', 'net.ipv4.ip_forward').at_least(:once).and_return('3', '1') 190 | expect(provider_class).to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=1') 191 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=1') 192 | 193 | apply!(Puppet::Type.type(:sysctl).new( 194 | name: 'net.ipv4.ip_forward', 195 | value: '1', 196 | apply: true, 197 | target: target, 198 | provider: 'augeas' 199 | )) 200 | 201 | augparse_filter(target, 'Sysctl.lns', 'net.ipv4.ip_forward', ' 202 | { "net.ipv4.ip_forward" = "1" } 203 | ') 204 | 205 | expect(@logs.first).not_to be_nil 206 | expect(@logs.first.message).to eq("changed configuration value from '0' to '1' and live value from '3' to '1'") 207 | end 208 | 209 | it 'updates value with augeas only' do 210 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('') 211 | expect(provider_class).not_to receive(:sysctl).with('-n', 'net.ipv4.ip_forward') 212 | expect(provider_class).not_to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=1') 213 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('') 214 | 215 | apply!(Puppet::Type.type(:sysctl).new( 216 | name: 'net.ipv4.ip_forward', 217 | value: '1', 218 | apply: false, 219 | target: target, 220 | provider: 'augeas' 221 | )) 222 | 223 | augparse_filter(target, 'Sysctl.lns', 'net.ipv4.ip_forward', ' 224 | { "net.ipv4.ip_forward" = "1" } 225 | ') 226 | 227 | expect(@logs.first).not_to be_nil 228 | expect(@logs.first.message).to eq("changed configuration value from '0' to '1'") 229 | end 230 | end 231 | 232 | context 'when system and config values are set to the same value' do 233 | it 'updates value with augeas and sysctl' do 234 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=0') 235 | expect(provider_class).to receive(:sysctl).with('-n', 'net.ipv4.ip_forward').at_least(:once).and_return('0', '1') 236 | expect(provider_class).to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=1') 237 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=1') 238 | 239 | apply!(Puppet::Type.type(:sysctl).new( 240 | name: 'net.ipv4.ip_forward', 241 | value: '1', 242 | apply: true, 243 | target: target, 244 | provider: 'augeas' 245 | )) 246 | 247 | augparse_filter(target, 'Sysctl.lns', 'net.ipv4.ip_forward', ' 248 | { "net.ipv4.ip_forward" = "1" } 249 | ') 250 | 251 | expect(@logs.first).not_to be_nil 252 | expect(@logs.first.message).to eq("changed configuration value from '0' to '1' and live value from '0' to '1'") 253 | end 254 | 255 | it 'updates value with augeas only' do 256 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('') 257 | expect(provider_class).not_to receive(:sysctl).with('-n', 'net.ipv4.ip_forward') 258 | expect(provider_class).not_to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=1') 259 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('') 260 | 261 | apply!(Puppet::Type.type(:sysctl).new( 262 | name: 'net.ipv4.ip_forward', 263 | value: '1', 264 | apply: false, 265 | target: target, 266 | provider: 'augeas' 267 | )) 268 | 269 | augparse_filter(target, 'Sysctl.lns', 'net.ipv4.ip_forward', ' 270 | { "net.ipv4.ip_forward" = "1" } 271 | ') 272 | 273 | expect(@logs.first).not_to be_nil 274 | expect(@logs.first.message).to eq("changed configuration value from '0' to '1'") 275 | end 276 | end 277 | 278 | context 'when only system value is set to target value' do 279 | it 'updates value with augeas only' do 280 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=1') 281 | expect(provider_class).to receive(:sysctl).with('-n', 'net.ipv4.ip_forward').twice.and_return('1') 282 | # Values not in sync, system update forced anyway 283 | expect(provider_class).to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=1').once.and_return('1') 284 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=1') 285 | 286 | apply!(Puppet::Type.type(:sysctl).new( 287 | name: 'net.ipv4.ip_forward', 288 | value: '1', 289 | apply: true, 290 | target: target, 291 | provider: 'augeas' 292 | )) 293 | 294 | augparse_filter(target, 'Sysctl.lns', 'net.ipv4.ip_forward', ' 295 | { "net.ipv4.ip_forward" = "1" } 296 | ') 297 | 298 | expect(@logs.first).not_to be_nil 299 | expect(@logs.first.message).to eq("changed configuration value from '0' to '1'") 300 | end 301 | 302 | it 'updates value with augeas only and never run sysctl' do 303 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('') 304 | expect(provider_class).not_to receive(:sysctl).with('-n', 'net.ipv4.ip_forward') 305 | expect(provider_class).not_to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=1') 306 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('') 307 | 308 | apply!(Puppet::Type.type(:sysctl).new( 309 | name: 'net.ipv4.ip_forward', 310 | value: '1', 311 | apply: false, 312 | target: target, 313 | provider: 'augeas' 314 | )) 315 | 316 | augparse_filter(target, 'Sysctl.lns', 'net.ipv4.ip_forward', ' 317 | { "net.ipv4.ip_forward" = "1" } 318 | ') 319 | 320 | expect(@logs.first).not_to be_nil 321 | expect(@logs.first.message).to eq("changed configuration value from '0' to '1'") 322 | end 323 | end 324 | 325 | context 'when only config value is set to target value' do 326 | it 'updates value with sysctl only' do 327 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=1') 328 | expect(provider_class).to receive(:sysctl).with('-n', 'net.ipv4.ip_forward').twice.and_return('1', '0') 329 | # Values not in sync, system update forced anyway 330 | expect(provider_class).to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=0').once.and_return('0') 331 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=0') 332 | 333 | apply!(Puppet::Type.type(:sysctl).new( 334 | name: 'net.ipv4.ip_forward', 335 | value: '0', 336 | apply: true, 337 | target: target, 338 | provider: 'augeas' 339 | )) 340 | 341 | augparse_filter(target, 'Sysctl.lns', 'net.ipv4.ip_forward', ' 342 | { "net.ipv4.ip_forward" = "0" } 343 | ') 344 | 345 | expect(@logs.first).not_to be_nil 346 | expect(@logs.first.message).to eq("changed live value from '1' to '0'") 347 | end 348 | 349 | it 'does not update value with sysctl' do 350 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=0') 351 | expect(provider_class).not_to receive(:sysctl).with('-n', 'net.ipv4.ip_forward') 352 | expect(provider_class).not_to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=0') 353 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=0') 354 | 355 | apply!(Puppet::Type.type(:sysctl).new( 356 | name: 'net.ipv4.ip_forward', 357 | value: '0', 358 | apply: false, 359 | target: target, 360 | provider: 'augeas' 361 | )) 362 | 363 | augparse_filter(target, 'Sysctl.lns', 'net.ipv4.ip_forward', ' 364 | { "net.ipv4.ip_forward" = "0" } 365 | ') 366 | 367 | expect(@logs.first).to be_nil 368 | end 369 | end 370 | 371 | context 'when updating comment' do 372 | it 'changes comment' do 373 | expect(provider_class).to receive(:sysctl).with(['-e', 'kernel.sysrq']).twice.and_return('kernel.sysrq=enables the SysRq feature') 374 | 375 | apply!(Puppet::Type.type(:sysctl).new( 376 | name: 'kernel.sysrq', 377 | comment: 'enables the SysRq feature', 378 | target: target, 379 | provider: 'augeas' 380 | )) 381 | 382 | aug_open(target, 'Sysctl.lns') do |aug| 383 | expect(aug.match("#comment[. = 'SysRq setting']")).not_to eq([]) 384 | expect(aug.match("#comment[. = 'kernel.sysrq: enables the SysRq feature']")).not_to eq([]) 385 | end 386 | end 387 | 388 | it 'removes comment' do 389 | expect(provider_class).to receive(:sysctl).with(['-e', 'kernel.sysrq']).twice.and_return('kernel.sysrq=enables the SysRq feature') 390 | 391 | apply!(Puppet::Type.type(:sysctl).new( 392 | name: 'kernel.sysrq', 393 | comment: '', 394 | target: target, 395 | provider: 'augeas' 396 | )) 397 | 398 | aug_open(target, 'Sysctl.lns') do |aug| 399 | expect(aug.match("#comment[. =~ regexp('kernel.sysrq:.*')]")).to eq([]) 400 | expect(aug.match("#comment[. = 'SysRq setting']")).not_to eq([]) 401 | end 402 | end 403 | end 404 | 405 | context 'when not persisting' do 406 | it 'does not persist the value on disk' do 407 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=0') 408 | expect(provider_class).to receive(:sysctl).with('-n', 'net.ipv4.ip_forward').twice.and_return('0', '1') 409 | expect(provider_class).to receive(:sysctl).with('-w', 'net.ipv4.ip_forward=1').once 410 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).and_return('net.ipv4.ip_forward=1') 411 | 412 | apply!(Puppet::Type.type(:sysctl).new( 413 | name: 'net.ipv4.ip_forward', 414 | value: '1', 415 | apply: true, 416 | target: target, 417 | provider: 'augeas', 418 | persist: false 419 | )) 420 | 421 | augparse_filter(target, 'Sysctl.lns', 'net.ipv4.ip_forward', ' 422 | { "net.ipv4.ip_forward" = "0" } 423 | ') 424 | 425 | expect(@logs.first).not_to be_nil 426 | expect(@logs.first.message).to eq("changed live value from '0' to '1'") 427 | end 428 | 429 | it 'does not add comment to the value on disk' do 430 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).twice.and_return('net.ipv4.ip_forward=1') 431 | 432 | apply!(Puppet::Type.type(:sysctl).new( 433 | name: 'net.ipv4.ip_forward', 434 | target: target, 435 | provider: 'augeas', 436 | persist: false, 437 | comment: 'This is a test' 438 | )) 439 | 440 | aug_open(target, 'Sysctl.lns') do |aug| 441 | expect(aug.get('net.ipv4.ip_forward')).to eq('0') 442 | expect(aug.get('#comment[4]')).to eq('Controls IP packet forwarding') 443 | end 444 | 445 | expect(@logs.first).to be_nil 446 | end 447 | end 448 | end 449 | 450 | context 'with small file' do 451 | let(:tmptarget) { aug_fixture('small') } 452 | let(:target) { tmptarget.path } 453 | 454 | describe 'when updating comment' do 455 | it 'adds comment' do 456 | expect(provider_class).to receive(:sysctl).with(['-e', 'net.ipv4.ip_forward']).twice.and_return('net.ipv4.ip_forward=1') 457 | 458 | apply!(Puppet::Type.type(:sysctl).new( 459 | name: 'net.ipv4.ip_forward', 460 | comment: 'test comment', 461 | target: target, 462 | provider: 'augeas' 463 | )) 464 | 465 | augparse(target, 'Sysctl.lns', ' 466 | { "#comment" = "Kernel sysctl configuration file" } 467 | { } 468 | { "#comment" = "For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and" } 469 | { "#comment" = "sysctl.conf(5) for more details." } 470 | { } 471 | { "#comment" = "Controls IP packet forwarding" } 472 | { "#comment" = "net.ipv4.ip_forward: test comment" } 473 | { "net.ipv4.ip_forward" = "0" } 474 | { } 475 | ') 476 | end 477 | end 478 | end 479 | 480 | context 'with broken file' do 481 | let(:tmptarget) { aug_fixture('broken') } 482 | let(:target) { tmptarget.path } 483 | 484 | it 'fails to load' do 485 | expect do 486 | apply!(Puppet::Type.type(:sysctl).new( 487 | name: 'net.ipv4.ip_forward', 488 | value: '1', 489 | target: target, 490 | provider: 'augeas' 491 | )) 492 | end.to raise_error(%r{target}) 493 | end 494 | end 495 | end 496 | --------------------------------------------------------------------------------