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

New module: remove_host #18596

Open
wants to merge 1 commit into
base: devel
from
Open

New module: remove_host #18596

wants to merge 1 commit into from

Conversation

@jpic
Copy link
Contributor

@jpic jpic commented Nov 23, 2016

ISSUE TYPE
  • Feature Pull Request
  • New Module Pull Request
COMPONENT NAME

remove_host

ANSIBLE VERSION
ansible 2.3.0 (remove_host f7f455dd84) last updated 2016/11/23 11:21:43 (GMT +200)
  lib/ansible/modules/core: (detached HEAD b598611afb) last updated 2016/11/23 11:23:32 (GMT +200)
  lib/ansible/modules/extras: (detached HEAD 25292b3ebd) last updated 2016/11/23 11:23:32 (GMT +200)
  config file = /home/jpic/.ansible.cfg
  configured module search path = ['/home/jpic/ansible/library', '/usr/share/ansible']
SUMMARY

Added remove_host module. This is for when a task actually destroys a host, then it can be removed from further plays.

lib/ansible/inventory/group.py Outdated Show resolved Hide resolved
@bcoca bcoca added this to the 2.3.0 milestone Nov 23, 2016
@bcoca
Copy link
Member

@bcoca bcoca commented Nov 23, 2016

making note of needing docs (module stub) once this is merged

jpic added a commit to jpic/ansible-modules-core that referenced this pull request Nov 25, 2016
@jpic
Copy link
Contributor Author

@jpic jpic commented Nov 25, 2016

Thanks for accepting this, but the test should fail, looks like this commit misses something to have it executed, any clue please ?

@gundalow
Copy link
Contributor

@gundalow gundalow commented Nov 25, 2016

@jpic The tests need referencing from test/integration/non_destructive.yml (assuming they are non destructive.

@jpic
Copy link
Contributor Author

@jpic jpic commented Nov 25, 2016

Thank you @gundalow ! Tests are running, but it can't find remote_host. Probably because it's missing from modules/core ? ansible/ansible-modules-core#5726

2016-11-25 18:10:03 ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

Locally it works great:

TASK [add_host] **************************************************************************************************************************************************
task path: /home/jpic/work/novapost/ansible-boot-lxc/test.yml:8
creating host via 'add_host': hostname=testboot.lxc
changed: [localhost] => {
    "add_host": {
        "groups": [
            "testboot"
        ], 
        "host_name": "testboot.lxc", 
        "host_vars": {
            "lxc_container_config": [
                "lxc.mount.entry=/home/jpic/work/novapost/ansible-boot-lxc srv none defaults,bind,create=dir,uid=0 0 0"
            ]
        }
    }, 
    "changed": true
}

TASK [debug] *****************************************************************************************************************************************************
task path: /home/jpic/work/novapost/ansible-boot-lxc/test.yml:13
ok: [localhost] => {
    "groups": {
        "all": [
            "testboot.lxc"
        ], 
        "testboot": [
            "testboot.lxc"
        ], 
        "ungrouped": [
            "localhost"
        ]
    }
}

TASK [remove_host] ***********************************************************************************************************************************************
task path: /home/jpic/work/novapost/ansible-boot-lxc/test.yml:14
changed: [localhost] => {
    "changed": true, 
    "remove_host": {
        "host_name": "testboot.lxc"
    }
}

TASK [debug] *****************************************************************************************************************************************************
task path: /home/jpic/work/novapost/ansible-boot-lxc/test.yml:16
ok: [localhost] => {
    "groups": {
        "all": [], 
        "testboot": [], 
        "ungrouped": [
            "localhost"
        ]
    }
}

Isn't the best thing to do now creating another branch with a submodule reference to my fork of core modules ?

@gundalow
Copy link
Contributor

@gundalow gundalow commented Nov 28, 2016

Changes to lib/ansible/modules/* must be in another PR, once merger we (Ansible Core Team) will update the submodules reference

Once the above is done this you can test this PR.

Please remove the change to lib/ansible/modules/core

The git submodule pain will be going away very shortly

Copy link
Contributor

@gundalow gundalow left a comment

needs_revision

test/integration/targets/remove_host/tasks/main.yml Outdated Show resolved Hide resolved
test/integration/targets/remove_host/tasks/main.yml Outdated Show resolved Hide resolved
@mattclay
Copy link
Member

@mattclay mattclay commented Dec 12, 2016

@jpic One of the test failures is due to a yamllint test failure:

test/integration/targets/remove_host/tasks/main.yml
  36:25     error    syntax error: mapping values are not allowed here
@gundalow
Copy link
Contributor

@gundalow gundalow commented Feb 7, 2017

rebase needed

@goneri goneri added the ci_verified label Oct 2, 2019
@jpic jpic force-pushed the jpic:remove_host branch from 40f90f0 to 9f0b91e Oct 5, 2019
@ansibot

This comment has been hidden.

@jpic jpic force-pushed the jpic:remove_host branch 2 times, most recently from 8a6d727 to 0684534 Oct 5, 2019
@ansibot

This comment has been hidden.

@jpic jpic force-pushed the jpic:remove_host branch from 5df6b1b to a03aed8 Oct 10, 2019
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.

- name: removing an unknown host should not fail
remove_host: name=remove_host_unknown_host

This comment has been minimized.

@tremble

tremble Oct 11, 2019
Contributor

Should we be asserting is not changed here?

This comment has been minimized.

@jpic

jpic Oct 11, 2019
Author Contributor

Well, that's what did the initial PR, but that's not possible anymore due to internal changes, the same way it's not possible for add_host:

$ cat test.yml 
#!/usr/bin/env ansible-playbook
- hosts: '*'
  tasks:
  - add_host: name=bar
    register: add_host0
  - debug: var=add_host0
  - add_host: name=bar
    register: add_host1
  - debug: var=add_host1


$ ansible-playbook  -i localhost, -c local test.yml 

PLAY [*] ******************************************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************
ok: [localhost]

TASK [add_host] ***********************************************************************************************************************************
changed: [localhost]

TASK [debug] **************************************************************************************************************************************
ok: [localhost] => {
    "add_host0": {
        "add_host": {
            "groups": [],
            "host_name": "bar",
            "host_vars": {}
        },
        "changed": true,
        "failed": false
    }
}

TASK [add_host] ***********************************************************************************************************************************
changed: [localhost]

TASK [debug] **************************************************************************************************************************************
ok: [localhost] => {
    "add_host1": {
        "add_host": {
            "groups": [],
            "host_name": "bar",
            "host_vars": {}
        },
        "changed": true,
        "failed": false
    }
}

PLAY RECAP ****************************************************************************************************************************************
localhost                  : ok=5    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

I did debug that to figure why:

  • there seems to be now way for the StrategyBase to communicate with the ActionModule,
  • even when result['changed'] is not explicitly set to True in the ActionModule, it will be set to True by default,
  • changing result_item['changed'] in the StrategyBase (which is what this PR did initially) has no effect on the returned result by the ActionModule anymore

- name: remove host from the runtime inventory
remove_host:
name: removedhost

This comment has been minimized.

@tremble

tremble Oct 11, 2019
Contributor

And similarly is changed

This comment has been minimized.

@jpic

jpic Oct 11, 2019
Author Contributor

Same issue as above unfortunately

@gundalow gundalow changed the title [WE WANT THIS] New module: remove_host New module: remove_host Oct 11, 2019
@jpic
Copy link
Contributor Author

@jpic jpic commented Oct 22, 2019

@gundalow is there any change request that is not implemented ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment