Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions cloudinit/config/cc_puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@
attributes and certificate extension requests.
See https://puppet.com/docs/puppet/latest/config_file_csr_attributes.html

The puppet service will be automatically enabled after installation. A manual
run can also be triggered by setting ``exec`` to ``true``, and additional
arguments can be passed to ``puppet agent`` via the ``exec_args`` key (by
default the agent will execute with the ``--test`` flag).
By default, the puppet service will be automatically enabled after installation
and set to automatically start on boot. To override this in favor of manual
puppet execution set ``start_service`` to ``false``.

A single manual run can be triggered by setting ``exec`` to ``true``, and
additional arguments can be passed to ``puppet agent`` via the ``exec_args``
key (by default the agent will execute with the ``--test`` flag).

**Internal name:** ``cc_puppet``

Expand All @@ -85,6 +88,7 @@
package_name: 'puppet'
exec: <true/false>
exec_args: ['--test']
start_service: <true/false>
conf:
agent:
server: "puppetserver.example.org"
Expand Down Expand Up @@ -197,6 +201,9 @@ def handle(name, cfg, cloud, log, _args):
puppet_cfg, 'install_type', 'packages')
cleanup = util.get_cfg_option_bool(puppet_cfg, 'cleanup', True)
run = util.get_cfg_option_bool(puppet_cfg, 'exec', default=False)
start_puppetd = util.get_cfg_option_bool(puppet_cfg,
'start_service',
default=True)
aio_install_url = util.get_cfg_option_str(
puppet_cfg, 'aio_install_url', default=AIO_INSTALL_URL)

Expand Down Expand Up @@ -291,7 +298,8 @@ def handle(name, cfg, cloud, log, _args):
default_flow_style=False))

# Set it up so it autostarts
_autostart_puppet(log)
if start_puppetd:
_autostart_puppet(log)

# Run the agent if needed
if run:
Expand All @@ -312,7 +320,8 @@ def handle(name, cfg, cloud, log, _args):
cmd.extend(PUPPET_AGENT_DEFAULT_ARGS)
subp.subp(cmd, capture=False)

# Start puppetd
subp.subp(['service', 'puppet', 'start'], capture=False)
if start_puppetd:
# Start puppetd
subp.subp(['service', 'puppet', 'start'], capture=False)

# vi: ts=4 expandtab
22 changes: 22 additions & 0 deletions tests/unittests/test_handler/test_handler_puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,28 @@ def test_puppet_runs_puppet_if_requested(self, m_subp, m_auto):
[mock.call(['puppet', 'agent', '--test'], capture=False)],
m_subp.call_args_list)

@mock.patch('cloudinit.config.cc_puppet.subp.subp', return_value=("", ""))
def test_puppet_starts_puppetd(self, m_subp, m_auto):
"""Run puppet with default args if 'exec' is set to True."""
mycloud = self._get_cloud('ubuntu')
cfg = {'puppet': {}}
cc_puppet.handle('notimportant', cfg, mycloud, LOG, None)
self.assertEqual(1, m_auto.call_count)
self.assertIn(
[mock.call(['service', 'puppet', 'start'], capture=False)],
m_subp.call_args_list)

@mock.patch('cloudinit.config.cc_puppet.subp.subp', return_value=("", ""))
def test_puppet_skips_puppetd(self, m_subp, m_auto):
"""Run puppet with default args if 'exec' is set to True."""
mycloud = self._get_cloud('ubuntu')
cfg = {'puppet': {'start_service': False}}
cc_puppet.handle('notimportant', cfg, mycloud, LOG, None)
self.assertEqual(0, m_auto.call_count)
self.assertNotIn(
[mock.call(['service', 'puppet', 'start'], capture=False)],
m_subp.call_args_list)

@mock.patch('cloudinit.config.cc_puppet.subp.subp', return_value=("", ""))
def test_puppet_runs_puppet_with_args_list_if_requested(self,
m_subp, m_auto):
Expand Down