actions = { 'apt_update': { 'command': 'apt-get update', 'needed_by': [ 'pkg_apt:', ], 'triggered': True, 'cascade_skip': False, }, } files = { '/etc/apt/apt.conf.d/50unattended-upgrades': { 'content_type': 'mako', 'source': 'apt.conf-unattended-upgrades', 'context': {'data': node.metadata.get('apt', {}).get('unattended-upgrades', {})} }, '/etc/apt/apt.conf.d/20auto-upgrades': { 'source': 'apt.conf-auto-upgrades', }, } directories = { '/etc/apt/sources.list.d': {}, } pkg_apt = { 'apt-transport-https': {}, 'unattended-upgrades': {}, } gpg_keys = set() for name, data in node.metadata.get('apt', {}).get('repos', {}).items(): files['/etc/apt/sources.list.d/{}.list'.format(name)] = { 'content_type': 'mako', 'content': "\n".join(data['items']), 'triggers': [ 'action:apt_update', ], } if 'key' in data: gpg_keys.add(data['key']) files['/etc/apt/sources.list.d/{}.list'.format(name)]['needs'] = [ 'action:add_gpg_key_{}'.format(data['key']), ] previous_action = None for key in gpg_keys: files['/etc/apt/gpg-keys/{}'.format(key)] = { 'source': 'gpg-keys/{}'.format(key), } action_name = 'add_gpg_key_{}'.format(key) action_item_name = 'action:' + action_name actions[action_name] = { 'command': 'apt-key add /etc/apt/gpg-keys/{}'.format(key), 'unless': 'apt-key export {} 2>/dev/null | grep -q "END PGP PUBLIC KEY BLOCK"'.format(key), 'cascade_skip': False, 'needed_by': ["action:apt_update"], 'needs': list(filter(None, [ 'file:/etc/apt/gpg-keys/{}'.format(key), previous_action, ])), } previous_action = action_item_name if node.metadata.get('apt', {}).get('packages', {}): for package, options in node.metadata['apt']['packages'].items(): pkg_apt[package] = options if node.metadata.get('keep-cloud-init', False): pkg_apt['cloud-init'] = { 'installed': True, } else: pkg_apt['cloud-init'] = { 'installed': False, } pkg_apt['netplan.io'] = { 'installed': False, } files['/etc/cloud'] = { 'delete': True, } files['/etc/netplan'] = { 'delete': True, } files['/var/lib/cloud'] = { 'delete': True, }