LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-03-2019, 02:31 AM   #1
ghpradeep
Member
 
Registered: Mar 2011
Posts: 32

Rep: Reputation: 0
need help on ansible vmware_vm_shell module


Hello Team,

I have created a small playbook to configure ip address on vm machine which is not on a network. basically, my playbook add network card to vm and configure static ip address on it. I am using vmware_vm_shell ansible module.

When i use root user and password. it configured ip address. how do i use a normal user with sudo access to configure ip address.

Please find below playbook.

ansible_sudo_user: is sudo user.

---
- hosts: all
gather_facts: false
become: yes
become_method: su
become_user: root
tasks:
- name: Adding Network Card Into VM {{ inventory_hostname }}
vmware_guest:
hostname: "{{ vsphere_host }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_password }}"
validate_certs: no
name: "{{ inventory_hostname }}"
state: present
force: yes
datacenter: "{{ data_center }}"
folder: "{{ folder_name }}"
networks:
- name: "{{ guest_network }}"
type: static
device_type: vmxnet3
start_connected: True
delegate_to: localhost
connection: local
tags:
- add_nic

- name: Power on VM {{ inventory_hostname }}
vmware_guest:
hostname: "{{ vsphere_host }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_password }}"
validate_certs: no
name: "{{ inventory_hostname }}"
state: poweredon
connection: local
delegate_to: localhost

- name: Wait for VMware tools to become available {{ inventory_hostname }}
vmware_guest_tools_wait:
hostname: "{{ vsphere_host }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_password }}"
validate_certs: no
name: "{{ inventory_hostname }}"
folder: "{{ folder_name }}"
delegate_to: localhost
connection: local


- name: Configure Network IP Address {{ inventory_hostname }}
vmware_vm_shell:
hostname: "{{ vsphere_host }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_password }}"
datacenter: "{{ data_center }}"
cluster: "{{ cluster_name }}"
validate_certs: False
folder: "{{ folder_name }}"
vm_id: "{{ inventory_hostname }}"
vm_username: "{{ ansible_sudo_user }}"
vm_password: "{{ ansible_sudo_pass }}"
vm_shell: /usr/bin/sudo
vm_shell_args: ' /usr/sbin/ifconfig "{{ nic1 }}" "{{ ansible_host }}" netmask "{{ mask }}" broadcast "{{ gw }}" up'
vm_shell_cwd: "/usr/sbin"
delegate_to: localhost
connection: local
tags:
- ip_config
 
Old 04-03-2019, 07:25 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
The playbook is practically unreadable. All leading spaces have been collapsed; do you expect people to read a YAML file without indentation?

Please edit your question and put code tags around the code. See my signature for instructions.

Having said that, your description is lacking. Which command did you issue to run this playbook, and what output did you get? Any failure messages? Is there a difference between the outputs of the successful and failing playbook runs?

Did you try adding --become to the ansible-playbook command?

As far as I know, you don't normally run playbooks as the root user. It seems to me that something is fundamentally wrong with your Ansible setup.

Last edited by berndbausch; 04-03-2019 at 07:30 PM. Reason: grammar, typos, added information
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: What you need to know about Ansible modules LXer Syndicated Linux News 0 03-04-2019 07:30 AM
LXer: Ansible Tutorial: Introduction to simple Ansible commands LXer Syndicated Linux News 0 05-21-2018 10:28 AM
LXer: Ansible Tutorial: Intorduction to simple Ansible commands LXer Syndicated Linux News 0 01-14-2018 05:37 PM
Ansible playbook and need tabbed spaces in fstab fusion1275 Linux - Newbie 3 09-21-2017 02:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 01:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration