I solved so:
---
- name: Create Linux VM
hosts: localhost
connection: local
gather_facts: no
tasks:
- name: Install Linux server
vmware_guest:
hostname: '{{ vcenter_server }}'
username: '{{ vcenter_user }}'
password: '{{ vcenter_password }}'
validate_certs: no
datacenter: '{{ vcenter_datacenter }}'
cluster: '{{ vcenter_cluster }}'
name: '{{ vcenter_guest }}'
template: Template_RHEL7
state: poweredon
folder: '/'
disk:
- size_gb: 35
type: thin
datastore: ds
autoselect_datastore: yes
networks:
- name: '{{ network_connection }}'
ip: '{{ ip_address }}'
netmask: '{{ ip_netmask }}'
gateway: '{{ ip_gateway }}'
start_connected: yes
customization:
domain: '{{ dns_domain }}'
dns_servers:
- 192.168.1.100
wait_for_ip_address: yes
delegate_to: 127.0.0.1
run_once: True
- name: Add host in group
add_host:
hostname: '{{ vcenter_guest }}'
groups: createvm_temp
ansible_host: '{{ ip_address }}'
with_items: '{{ vcenter_guest }}'
- name: Post create vm
hosts: createvm_temp
gather_facts: no
tasks:
- name: Register to RHN and auto-subscribe to available content.
become: yes
redhat_subscription:
state: present
username: user
password: pass
auto_attach: true
I hope is usefully also to others.
On Monday, 20 August 2018 15:06:37 UTC+2, Jonathan Lozada De La Matta wrote:
>
> try
> https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#turning-off-facts
>
>
> On Mon, Aug 20, 2018 at 8:38 AM Enzo <[email protected] <javascript:>>
> wrote:
>
>> Thank you Jonathan for your suggestion.
>>
>> Now I have this playbook:
>>
>> ---
>> - name: Create Linux VM
>> hosts: localhost
>> connection: local
>> gather_facts: True
>>
>> tasks:
>> - name: Install Linux server
>> vmware_guest:
>> hostname: '{{ vcenter_server }}'
>> username: '{{ vcenter_user }}'
>> password: '{{ vcenter_password }}'
>> validate_certs: no
>> datacenter: '{{ vcenter_datacenter }}'
>> cluster: '{{ vcenter_cluster }}'
>> name: '{{ vcenter_guest }}'
>> template: Template_RHEL7
>> state: poweredon
>> folder: '/'
>> disk:
>> - size_gb: 35
>> type: thin
>> datastore: ds
>> autoselect_datastore: yes
>> networks:
>> - name: '{{ network_connection }}'
>> ip: '{{ ip_address }}'
>> netmask: '{{ ip_netmask }}'
>> gateway: '{{ ip_gateway }}'
>> start_connected: yes
>> customization:
>> domain: '{{ dns_domain }}'
>> dns_servers:
>> - 192.168.0.100
>> wait_for_ip_address: yes
>> delegate_to: 127.0.0.1
>> run_once: True
>>
>> - name: Add host in group
>> add_host:
>> hostname: '{{ vcenter_guest }}'
>> groupname: createvm_temp
>> with_items: '{{ vcenter_guest }}'
>>
>> # - name: Wait for ssh to come up
>> # wait_for: host={{ ip_address }} port=22 delay=10 timeout=120
>> # with_items: '{{ vcenter_guest }}'
>>
>> - name: Setting ip as instance fact
>> set_fact: host={{ ip_address }}
>> with_items: '{{ vcenter_guest }}'
>>
>> - name: Register to RHN and auto-subscribe to available content.
>> hosts: createvm_temp
>> gather_facts: True
>> redhat_subscription:
>> state: present
>> username: user
>> password: password
>> auto_attach: true
>> with_items: '{{ vcenter_guest }}'
>>
>> I'm running with ansible version 2.6.2, I got 2 warnings
>>
>> [WARNING]: Ignoring invalid attribute: gather_facts
>> [WARNING]: Ignoring invalid attribute: hosts
>>
>> and an error
>>
>> TASK [Register to RHN and auto-subscribe to available content.]
>> **************** 11:39:47
>> failed: [localhost] (item=ansibletest) => {"changed": false, "item":
>> "ansibletest", "msg": "Failed to find required executable
>> subscription-manager in paths:
>> /opt/awx/embedded/bin:/opt/awx/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin"}
>>
>>
>>
>> Ansible is running on centos 7 where subscription-manager is not
>> installed, while on target ansibletest RHEL7 is installed but ansible
>> tell me no.
>> I think the issue is because the task is executed on localhost and not on
>> new host so I can't change the host when run all other tasks.
>> Other suggestions?
>>
>> Thank you
>> Enzo
>>
>> On Sunday, 19 August 2018 17:49:23 UTC+2, Jonathan Lozada De La Matta
>> wrote:
>>>
>>> you need to put add_host to it adds the vm created to the current
>>> inventory then do the RHN part. This blog has a good explanation
>>>
>>> https://www.redhat.com/en/blog/creating-load-balanced-web-service-cloud-ansible
>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/98341a9b-80b4-4f98-8b49-af85517eea76%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/98341a9b-80b4-4f98-8b49-af85517eea76%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> --
>
> Jonathan lozada de la matta
>
> AUTOMATION CONSULTANT - AUTOMATION PRACTICE
>
> Red Hat Consulting Services <https://www.redhat.com/>
>
> [email protected] <javascript:>
>
>
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/4884965f-3634-46e5-a0d4-c78c525b266a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.