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

add an option for tower_host to merge variables instead of replacing #41687

Closed
orgito opened this issue Jun 19, 2018 · 8 comments
Closed

add an option for tower_host to merge variables instead of replacing #41687

orgito opened this issue Jun 19, 2018 · 8 comments
Labels
affects_2.5 This issue/PR affects Ansible v2.5 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. tower Tower community web_infrastructure Web-infrastructure category

Comments

@orgito
Copy link
Contributor

orgito commented Jun 19, 2018

SUMMARY

I want to use the tower_host module to add/replace one specific variable of an existing host in tower. Currently the module will remove all existing variables from the host leaving only the variable specified in the task.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

tower_host

ANSIBLE VERSION
ansible 2.5.5
CONFIGURATION
ANSIBLE_PIPELINING(/home/renato/.ansible.cfg) = True
ANSIBLE_SSH_ARGS(/home/renato/.ansible.cfg) = -C -o ControlMaster=auto -o ControlPersist=60s -o ForwardAgent=yes
ANSIBLE_SSH_CONTROL_PATH(/home/renato/.ansible.cfg) = %(directory)s/ansible-ssh-%%C
CACHE_PLUGIN(/home/renato/.ansible.cfg) = redis
CACHE_PLUGIN_TIMEOUT(/home/renato/.ansible.cfg) = 86100
DEFAULT_FILTER_PLUGIN_PATH(/home/renato/.ansible.cfg) = [u'/home/renato/ansible/plugins/filter_plugins']
DEFAULT_FORKS(/home/renato/.ansible.cfg) = 15
DEFAULT_GATHERING(/home/renato/.ansible.cfg) = smart
DEFAULT_HOST_LIST(/home/renato/.ansible.cfg) = [u'/home/renato/ansible/hosts']
DEFAULT_REMOTE_USER(/home/renato/.ansible.cfg) = root
DEFAULT_ROLES_PATH(/home/renato/.ansible.cfg) = [u'/home/renato/ansible/roles']
DEFAULT_VAULT_PASSWORD_FILE(/home/renato/.ansible.cfg) = /home/renato/ansible/.vault-passwd.sh
HOST_KEY_CHECKING(/home/renato/.ansible.cfg) = False
OS / ENVIRONMENT

Ansible Host: Fedora 28 with ansible-tower-cli (3.3.0)
Tower Test Host: Centos 7.5.1804 / AWX 1.0.6.16

STEPS TO REPRODUCE

Task to add/replace a variable to an existing tower host.

  - name: Update host in Tower
    tower_host:
      name: "{{ inventory_hostname }}"
      inventory: "Telecom Hosts - Production"
      variables:
        vm_uuid: "{{facts.instance.hw_product_uuid}}"
      tower_verify_ssl: no
    connection: local

In order not to change the current behavior, which potentially breaks existing playbooks, maybe there should be a new parameter, like merge_variable, to specify that the variable(s) should be added and not completely replace existing variables:

  - name: Update host in Tower
    tower_host:
      name: "{{ inventory_hostname }}"
      inventory: "Telecom Hosts - Production"
      merge_variables: yes     
      variables:
        vm_uuid: "{{facts.instance.hw_product_uuid}}"
      tower_verify_ssl: no
    connection: local
EXPECTED RESULTS

The vm_uuid variable should be added to the existing list of variables if it is not already there or changed if already there and different. Any other variables should not be touched

ACTUAL RESULTS

The module delete all the existing variables and keep only the variables specified in the task.

@ansibot
Copy link
Contributor

ansibot commented Jun 19, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Jun 19, 2018

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Jun 19, 2018
@AlanCoding
Copy link
Member

I would consider this first as a feature in tower-cli, and then update the tower modules to use that call pattern (which possibly some version detection). The approach should be the same as:

ansible/tower-cli#552

That was done to solve a slightly different problem, but it handles the variable merging behavior at the correct point. The tower-cli library already does a preliminary request to get the object, and you need to modify data here to have the changed status remain accurate.

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Jun 19, 2018
@orgito
Copy link
Contributor Author

orgito commented Jun 20, 2018

So, the idea would be something like:

tower-cli host modify --name="myhost" --subinput vm_uuid xxxxxxxxxx

Possibly with multiple --subinput if there are multiple variables. Then we could change the ansible module to have a parameter to toggle subinput use.

Any idea when will that land in tower-cli?

@AlanCoding
Copy link
Member

This is such a high-impact detail across all the resources in AWX that I want to get it right. I would probably call it something different in this case, it might look like:

tower-cli host modify --name="myhost" --variable vm_uuid xxxxxxxxxx --variable vm_user xxxxxxxxxx

Then if we do it like this, the call pattern from python would look like:

import tower_cli
res = tower_cli.get_resource('host')
res.modify(name="myhost", variable=(('vm_uuid', 'xxxx'), ('vm_user', 'xxxx')))

We might be able to have --variable as a CLI alias but have variables as the function keyword argument. That would probably be ideal, and it would be good to do the same thing with subinput / subinputs.

My first interest here is credentials, but there are already bugs related to sub-fields of JSON/YAML fields in notification templates. Then, the same feature request would apply to all inventory things, job templates, etc.

I'm not sure what the timeline will be, but the related credentials fix is somewhat of a priority.

@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed support:community This issue/PR relates to code supported by the Ansible community. labels Sep 16, 2018
@ansibot ansibot added support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 2, 2018
@dagwieers dagwieers added the tower Tower community label Feb 8, 2019
@ansibot ansibot added the web_infrastructure Web-infrastructure category label Feb 16, 2019
@ansibot
Copy link
Contributor

ansibot commented Mar 12, 2019

@ansibot
Copy link
Contributor

ansibot commented Jun 8, 2019

@AlanCoding
Copy link
Member

Right now @ryanpetrello is working on the new AWX CLI. Until a CLI starts to support variable merges, I would rather not put it into consideration for the modules. As I've been saying in other issues here, we are migrating these modules out of core into an independent collection at https://github.com/ansible/awx/tree/devel/awx_collection. You can re-open another request in that issue queue, but I don't personally find this issue compelling enough right now to migrate over.

close_me

@ansibot ansibot closed this as completed Oct 30, 2019
@ansible ansible locked and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 feature This issue/PR relates to a feature request. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. tower Tower community web_infrastructure Web-infrastructure category
Projects
None yet
Development

No branches or pull requests

4 participants