Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Change ansible pull module type from dict to list #6010

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
55 changes: 29 additions & 26 deletions cloudinit/config/cc_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ def validate_config(cfg: dict):
for key in required_keys:
if not get_cfg_by_path(cfg, key):
raise ValueError(f"Missing required key '{key}' from {cfg}")
if cfg.get("pull"):
for key in "pull/url", "pull/playbook_name":
if not get_cfg_by_path(cfg, key):
raise ValueError(f"Missing required key '{key}' from {cfg}")
pull_cfg = cfg.get("pull")
if pull_cfg:
for c in pull_cfg:
for key in "url", "playbook_name":
if not get_cfg_by_path(c, key):
raise ValueError(f"Missing required key '{key}' from {c}")

controller_cfg = cfg.get("setup_controller")
if controller_cfg:
Expand All @@ -210,28 +212,29 @@ def filter_args(cfg: dict) -> dict:
}


def run_ansible_pull(pull: AnsiblePull, cfg: dict):
playbook_name: str = cfg.pop("playbook_name")

v = pull.get_version()
if not v:
LOG.warning("Cannot parse ansible version")
elif v < lifecycle.Version(2, 7, 0):
# diff was added in commit edaa0b52450ade9b86b5f63097ce18ebb147f46f
if cfg.get("diff"):
raise ValueError(
f"Ansible version {v.major}.{v.minor}.{v.patch}"
"doesn't support --diff flag, exiting."
)
stdout = pull.pull(
*[
f"--{key}={value}" if value is not True else f"--{key}"
for key, value in filter_args(cfg).items()
],
playbook_name,
)
if stdout:
sys.stdout.write(f"{stdout}")
def run_ansible_pull(pull: AnsiblePull, cfg: list):
for c in cfg: # Get every playbook_name and url in cfg list
playbook_name: str = c.pop("playbook_name")

v = pull.get_version()
if not v:
LOG.warning("Cannot parse ansible version")
elif v < lifecycle.Version(2, 7, 0):
# diff was added in commit edaa0b52450ade9b86b5f63097ce18ebb147f46f
if c.get("diff"):
raise ValueError(
f"Ansible version {v.major}.{v.minor}.{v.patch}"
"doesn't support --diff flag, exiting."
)
stdout = pull.pull(
*[
f"--{key}={value}" if value is not True else f"--{key}"
for key, value in filter_args(c).items()
],
playbook_name,
)
if stdout:
sys.stdout.write(f"{stdout}")


def ansible_galaxy(cfg: dict, ansible: AnsiblePull):
Expand Down
157 changes: 80 additions & 77 deletions cloudinit/config/schemas/schema-cloud-config-v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -866,83 +866,86 @@
"default": "ansible"
},
"pull": {
"required": [
"url",
"playbook_name"
],
"type": "object",
"additionalProperties": false,
"properties": {
"accept_host_key": {
"type": "boolean",
"default": false
},
"clean": {
"type": "boolean",
"default": false
},
"full": {
"type": "boolean",
"default": false
},
"diff": {
"type": "boolean",
"default": false
},
"ssh_common_args": {
"type": "string"
},
"scp_extra_args": {
"type": "string"
},
"sftp_extra_args": {
"type": "string"
},
"private_key": {
"type": "string"
},
"checkout": {
"type": "string"
},
"module_path": {
"type": "string"
},
"timeout": {
"type": "string"
},
"url": {
"type": "string"
},
"connection": {
"type": "string"
},
"vault_id": {
"type": "string"
},
"vault_password_file": {
"type": "string"
},
"verify_commit": {
"type": "boolean",
"default": false
},
"inventory": {
"type": "string"
},
"module_name": {
"type": "string"
},
"sleep": {
"type": "string"
},
"tags": {
"type": "string"
},
"skip_tags": {
"type": "string"
},
"playbook_name": {
"type": "string"
"type": "array",
"items": {
"required": [
"url",
"playbook_name"
],
"type": "object",
"additionalProperties": false,
"properties": {
"accept_host_key": {
"type": "boolean",
"default": false
},
"clean": {
"type": "boolean",
"default": false
},
"full": {
"type": "boolean",
"default": false
},
"diff": {
"type": "boolean",
"default": false
},
"ssh_common_args": {
"type": "string"
},
"scp_extra_args": {
"type": "string"
},
"sftp_extra_args": {
"type": "string"
},
"private_key": {
"type": "string"
},
"checkout": {
"type": "string"
},
"module_path": {
"type": "string"
},
"timeout": {
"type": "string"
},
"url": {
"type": "string"
},
"connection": {
"type": "string"
},
"vault_id": {
"type": "string"
},
"vault_password_file": {
"type": "string"
},
"verify_commit": {
"type": "boolean",
"default": false
},
"inventory": {
"type": "string"
},
"module_name": {
"type": "string"
},
"sleep": {
"type": "string"
},
"tags": {
"type": "string"
},
"skip_tags": {
"type": "string"
},
"playbook_name": {
"type": "string"
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions doc/examples/cloud-config-ansible-pull.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ packages:
ansible:
install_method: pip
pull:
url: "https://github.com/holmanb/vmboot.git"
playbook_name: ubuntu.yml
- url: "https://github.com/holmanb/vmboot.git"
playbook_name: ubuntu.yml
Loading