Re: [ansible-project] shell: umask 0022 not working

2020-01-10 Thread Masudur Rahman
Thank you very much. It worked like a charm. 

On Thursday, January 9, 2020 at 10:12:38 AM UTC-8, Kai Stian Olstad wrote:
>
> On 09.01.2020 18:32, Masudur Rahman wrote: 
> >- name: Change Umask to 0022 to make installer working 
> >  shell: umask 0022 && umask 
> > 
> >- name: Generic question with multiple different responses 
> >  expect: 
> >echo: yes 
> >command: ./{{ version }} --mode text 
> --disable_glibcxx_version_check 1 
> >chdir: /home/app/installers/ 
>
> As Brian mention, thing set it one task is not propagated to the next. 
> umask is a built in shell feature and the expect module is Python with no 
> way of setting umask. 
> So you have a least two alternatives, setting the umask before running 
> ansible-playbook or use bash/sh to execute the command in expect. 
>
>command: bash -c "umask 0022; ./{{ version }} --mode text 
> --disable_glibcxx_version_check 1" 
>
>
> >responses: 
> >  Question: 
> >'Please choose an option': '2' 
> >'\[\/opt\/app\]': '\n' 
> >'Backup Directory \[\/opt\/app\]': '/home/app/backup/' 
> >'Password ': 'Password' 
> >'Do you want to continue\? \[Y\/n\]': 'y' 
> > 
>
> This will not work, question is the actual key in you dict and not a 
> parameter you can use with expect. 
> Correct code would be: 
>
>responses: 
>  'Please choose an option': '2' 
>  '\[\/opt\/app\]': '\n' 
>  'Backup Directory \[\/opt\/app\]': '/home/app/backup/' 
>  'Password ': 'Password' 
>  'Do you want to continue\? \[Y\/n\]': 'y' 
>
> -- 
> Kai Stian Olstad 
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1f437044-ce62-4d35-9fd0-5308787ef126%40googlegroups.com.


Re: [ansible-project] equality not consistent

2020-01-10 Thread shaun
This seems to have been some sort of quoting issue.

After much troubleshooting, I found the working solution:

  changed_when:
- ((jjb_update.stderr_lines | regex_replace('.*jobs
updated.\\s+(\\d+).*', '\\1')) != '0' )

--
Shaun


On Sat, Nov 30, 2019 at 1:30 AM Kai Stian Olstad <
ansible-project+l...@olstad.com> wrote:

> On 30.11.2019 00:16, senorsmile wrote:
> > - hosts: localhost
> >gather_facts: False
> >tasks:
> >
> >- name: Update Jenkins-Jobs on Jenkins Master - docker container
> >  command: |
> >echo "INFO:jenkins_jobs.cli.subcommand.update:Updating jobs in
> > ['./jobs/'] ([])
> >  INFO:root:Caching type parameters of parameters =
> > jenkins_jobs.modules.parameters:Parameters
> >  INFO:root:Caching type builders of builders =
> > jenkins_jobs.modules.builders:Builders
> >  INFO:jenkins_jobs.builder:Number of jobs generated:  1
> >  INFO:jenkins_jobs.cli.subcommand.update:Number of jobs
> updated:
> > 0
> >  INFO:jenkins_jobs.builder:Number of views generated:  0
> >  INFO:jenkins_jobs.cli.subcommand.update:Number of views
> > updated: 0
> >"
> >  register: jjb_update
> >  changed_when:
> >- ( jjb_update.stdout_lines | regex_replace('.*jobs
> updated.\s+(\d+).*', '\1') != '0' )
>
> jjb_update.stdout_lines is a list and the regex_replace filter work on
> strings, so it probably should have failed.
>
> You can use the search test instead on stdout
>
>changed_when: jjb_update.stdout is not search('jobs updated:.0')
>
> --
> Kai Stian Olstad
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Ansible Project" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ansible-project/RXmtqMg_pl4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/92a3f484-9739-ae82-37eb-237e306277f5%40olstad.com
> .
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAMQv9hDagUf6F4rNi%3D2PH%2B%2BaByDsFe-mtKVz%2BgACHNKY9V9OpQ%40mail.gmail.com.


[ansible-project] Re: How to configure prompt with 2 inputs

2020-01-10 Thread Phil Griffiths
try this?

 name: reboot ios device
  cli_command:
command: reload
prompt:
  - Save?
  - confirm
answer:
 - y
 - y



On Friday, 10 January 2020 14:28:23 UTC, Srinivas Naram wrote:
>
> Hello Gurus
>
> I am working on ios_command module. This modules facilitates in execute 
> commands on Cisco IOS devices.
>
> While running 'reload' command it is prompting for 2 inputs, 
>
> "System configuration has been modified. Save? [yes/no]" > yes
> "Proceed with reload? [confirm]   > return character here
>
> I tried using prompts, but looks like it does not support providing 
> answers for 2 questions in 1 command. Tried expect module (could not get 
> this working)
>
> Any suggestions?
>
> My code snippet:
>
> ios_command:
>commands:
>- command: 'reload'
>  prompt:
>  -  "System configuration has been modified. Save? [yes/no]" 
>  -  "Proceed with reload? [confirm] 
> answer:
>- "\r"
>- 'yes'
>
>
>   
>
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/5f7e1ebb-3cd3-4fa4-9d15-7814a9597e23%40googlegroups.com.


Re: [ansible-project] Question: How to use the same host for multiple groups?

2020-01-10 Thread Konstantinos Tzevelekidis
Hello,

What I want to have is one host folder (i.e. Host1) which will contain a 
vars.yml that will define the actual ansible_host (i.e. "1.2.3.4"). So, in the 
inventory I will need to have:
[GroupA]
host1A ansible_host=Host1

[GroupB]
host1B ansible_host=Host1

where the ansible_host will take the name of the host folder (i.e. Host1) and 
will find the actual value for the ansible_host (i.e. "1.2.3.4") from the 
vars.yml.
What I understood is that by using the ansible_host variable in the inventory I 
have to give the actual value (i.e. "1.2.3.4") and it cannot take let's say a 
host alias (i.e. Host1).

Is there any other way to define which host folder to check in order to 
retrieve the ansible_host variable?

Best Regards,
Konstantinos

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6672d0f9-a84a-4e99-8602-05e31a1b089c%40googlegroups.com.


Re: [ansible-project] Question: How to use the same host for multiple groups?

2020-01-10 Thread Brian Coca
ansible_host is just a variable, you can define it anywhere you want.


-- 
--
Brian Coca

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7e_JY4LHOs6On%3D5vaWTK6se%3Dj47z5_fUmywfG2wyrUeFw%40mail.gmail.com.


Re: [ansible-project] How to pass information/variable while creating VM on esxxi server using Vmware_guest module

2020-01-10 Thread Abhijeet Kasurde
Hi Rohan,

There are a number of ways to do this.

Take a look at Prompts -
https://docs.ansible.com/ansible/latest/user_guide/playbooks_prompts.html
which will be interactive like you explained in the original post.

But going forward you might want to use VMware guest templates and OVF
images to customize and create new VMs. Take a look at "Clone from VM" and
"Clone from template" in VMware. vmware_guest also allows specifying
customization specification created in vCenter Customization Specification
Manager.

Also, as Naveen S suggested, you can also take a look at this

role which is a good start point.

Thanks,

On Fri, Jan 10, 2020 at 7:07 PM Rohan Kalap  wrote:

> Hello,
>
> I am looking to create VM from vmware_guest module on esxi server which is
> working fine with following playbook,
> But- I want to pass details which are needed while booting into VM e.g
> hostname, username or license agreement.
>
> I tried using
> 1-custome values and
> 2-set_facts but this doesn't work under vmware_guest module
>
> is there any way to automate OS installation by providing variables?
>
> this is my playbook-
> ---
> - hosts: localhost
>   gather_facts: no
>   tasks:
>   - debug:
>   msg: connection to host machine successful
>
>   - name: create test1 vm from esxi server
> #expect:
> #command: "configuration file!"
> #responses:
> #'PRESS \ TO CONTINUE:': ''
> vmware_guest:
>   hostname: "x.x.x.x"
>   username: "root"
>   password: "password"
>   validate_certs: no
>   folder: /ha-datacenter/vm/
>   name: "test-vm"
>   state: poweredon
>   guest_id: centos64Guest
>   esxi_hostname: "hostname"
>   disk:
>   - size_gb: 160
> type: thin
> datastore: datastore1
>   hardware:
> memory_mb: 3000
> num_cpus: 4
> scsi: paravirtual
>   cdrom:
> type: iso
> iso_path: "[datastore1] centos.iso"
> #  expect:
> #  command: "configuration!"
> #  responses:
> #'PRESS \ TO CONTINUE:': ''
>
> customization:
> # i tried using customization attribute but of no use
> hostname: "hostname"
> domain: "network"
>   networks:
>   - name: VM Network
> mac: aa:bb:dd:aa:00:23
> ip: x.x.x.x
> netmask: 255.255.255.0
> device_type: vmxnet3
>   wait_for_ip_address: yes
> delegate_to: localhost
> register: deploy_vm
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/3713e737-2147-4978-9fcb-28a22f371ee2%40googlegroups.com
> 
> .
>


-- 
Thanks,
Abhijeet Kasurde

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAFwWkHqt3jqx6XdTJytcuM2SWUAts4vD7kBxxUA2g9VMpK28EA%40mail.gmail.com.


[ansible-project] How to configure prompt with 2 inputs

2020-01-10 Thread Srinivas Naram
Hello Gurus

I am working on ios_command module. This modules facilitates in execute 
commands on Cisco IOS devices.

While running 'reload' command it is prompting for 2 inputs, 

"System configuration has been modified. Save? [yes/no]" > yes
"Proceed with reload? [confirm]   > return character here

I tried using prompts, but looks like it does not support providing answers 
for 2 questions in 1 command. Tried expect module (could not get this 
working)

Any suggestions?

My code snippet:

ios_command:
   commands:
   - command: 'reload'
 prompt:
 -  "System configuration has been modified. Save? [yes/no]" 
 -  "Proceed with reload? [confirm] 
answer:
   - "\r"
   - 'yes'


  

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/55decc88-5c4b-4e7a-a354-4f8a076384e7%40googlegroups.com.


Re: [ansible-project] How to pass information/variable while creating VM on esxxi server using Vmware_guest module

2020-01-10 Thread naveen s
Hello Rohan,

it is always better to have the variables and its values in the group_vars
section and pass them while executing the playbook.

1. created a reusable playbook (create a variable inside the playbook in
which you want to pass it at the time of playbook execution).
2. create a group_vars directory and create the vars.yml for all the
variables values

please find the attachment for the code to launch a linux server in vmware.

and also refer my github page for the vmware playbooks if need anything.

https://github.com/naveensangadala/Devops-Ansible-Playbooks-for-VMware-AWS-Azure-Cloud


Thanks & Regards,
Naveen Sangadala
(+91 7676257193)


On Fri, Jan 10, 2020 at 7:07 PM Rohan Kalap  wrote:

> Hello,
>
> I am looking to create VM from vmware_guest module on esxi server which is
> working fine with following playbook,
> But- I want to pass details which are needed while booting into VM e.g
> hostname, username or license agreement.
>
> I tried using
> 1-custome values and
> 2-set_facts but this doesn't work under vmware_guest module
>
> is there any way to automate OS installation by providing variables?
>
> this is my playbook-
> ---
> - hosts: localhost
>   gather_facts: no
>   tasks:
>   - debug:
>   msg: connection to host machine successful
>
>   - name: create test1 vm from esxi server
> #expect:
> #command: "configuration file!"
> #responses:
> #'PRESS \ TO CONTINUE:': ''
> vmware_guest:
>   hostname: "x.x.x.x"
>   username: "root"
>   password: "password"
>   validate_certs: no
>   folder: /ha-datacenter/vm/
>   name: "test-vm"
>   state: poweredon
>   guest_id: centos64Guest
>   esxi_hostname: "hostname"
>   disk:
>   - size_gb: 160
> type: thin
> datastore: datastore1
>   hardware:
> memory_mb: 3000
> num_cpus: 4
> scsi: paravirtual
>   cdrom:
> type: iso
> iso_path: "[datastore1] centos.iso"
> #  expect:
> #  command: "configuration!"
> #  responses:
> #'PRESS \ TO CONTINUE:': ''
>
> customization:
> # i tried using customization attribute but of no use
> hostname: "hostname"
> domain: "network"
>   networks:
>   - name: VM Network
> mac: aa:bb:dd:aa:00:23
> ip: x.x.x.x
> netmask: 255.255.255.0
> device_type: vmxnet3
>   wait_for_ip_address: yes
> delegate_to: localhost
> register: deploy_vm
>
> --
> 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 ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/3713e737-2147-4978-9fcb-28a22f371ee2%40googlegroups.com
> 
> .
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAD41bmMpGu5uHEPP0a6ERBcES-JgwevKui3YZ%3DJ3aCbvtqEpYg%40mail.gmail.com.
- hosts: vm-linux
  vars_files:
- "group_vars/{{ostype}}/{{config}}.yml"

  tasks:
- name: "Naveen the template I have taken is:"
  debug:
var: vmtemplate

- name: "PROVISION | Create Linux {{vmname}} from template {{ostype}} 
{{config}}"
  vmware_guest:
   validate_certs: false
   hostname: "{{ vcenter_host }}"
   username: "{{ vcenter_username }}"
   password: "{{ vcenter_password }}"
   datacenter: "{{ datacenter }}"
   name: "{{ vmname }}"
   folder: "{{ folder }}"
   template: "{{ vmtemplate }}"
   state: poweredon
   esxi_hostname: "{{ esxi_host }}"
  hardware:
 num_cpus: "{{ cpu }}"
 memory_mb: "{{ mem_mb }}"
  disk:
 - size_gb: "{{ disk }}"
   type: thin
   datastore: "{{ datastore }}"
  register: new_vm

- name: "NETWORK | Set the IP address and Netmask"
  local_action:
   module: vmware_vm_shell
   hostname: "{{ vcenter_host }}"
   username: "{{ vcenter_username }}"
   password: "{{ vcenter_password }}"
   datacenter: "{{ datacenter }}"
   vm_id: "{{ vmname }}"
   vm_username: "{{ v_username }}"
   vm_password: "{{ v_password }}"
   vm_shell: /usr/sbin/ifconfig
   vm_shell_args: " eth0 ipaddress netmask netmaskaddress "
   vm_shell_env:
 - "PATH=/bin"
   vm_shell_cwd: "/tmp"
   validate_certs: False
- name: "NETWORK | add the default gateway"
  local_action:
   module: vmware_vm_shell
   hostname: "{{ vcenter_host }}"
   username: "{{ 

[ansible-project] How to pass information/variable while creating VM on esxxi server using Vmware_guest module

2020-01-10 Thread Rohan Kalap
Hello,

I am looking to create VM from vmware_guest module on esxi server which is 
working fine with following playbook,
But- I want to pass details which are needed while booting into VM e.g 
hostname, username or license agreement.

I tried using 
1-custome values and 
2-set_facts but this doesn't work under vmware_guest module

is there any way to automate OS installation by providing variables?

this is my playbook-
---
- hosts: localhost
  gather_facts: no
  tasks:
  - debug:
  msg: connection to host machine successful

  - name: create test1 vm from esxi server
#expect:
#command: "configuration file!"
#responses:
#'PRESS \ TO CONTINUE:': ''
vmware_guest:
  hostname: "x.x.x.x"
  username: "root"
  password: "password"
  validate_certs: no
  folder: /ha-datacenter/vm/
  name: "test-vm"
  state: poweredon
  guest_id: centos64Guest
  esxi_hostname: "hostname"
  disk:
  - size_gb: 160
type: thin
datastore: datastore1
  hardware:
memory_mb: 3000
num_cpus: 4
scsi: paravirtual
  cdrom:
type: iso
iso_path: "[datastore1] centos.iso"
#  expect:
#  command: "configuration!"
#  responses:
#'PRESS \ TO CONTINUE:': ''
  
customization: 
# i tried using customization attribute but of no use
hostname: "hostname"
domain: "network"
  networks:
  - name: VM Network
mac: aa:bb:dd:aa:00:23
ip: x.x.x.x
netmask: 255.255.255.0
device_type: vmxnet3
  wait_for_ip_address: yes
delegate_to: localhost
register: deploy_vm

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3713e737-2147-4978-9fcb-28a22f371ee2%40googlegroups.com.


Re: [ansible-project] Question: How to use the same host for multiple groups?

2020-01-10 Thread Konstantinos Tzevelekidis
Hello,

Thanks a lot for your help! From what I understand is that the ansible_host 
should be the actual hostname (dns entry). Is there any way to pass the to the 
ansible_host the name of an entry in the host_vars?

For example, I have in the host_vars directory, the folder Host1 where it has a 
vars.yml where one of the variables is ansible_host: "1.2.3.4".
In order to use your approach I will need to add the ansible_host inline in the 
inventory like this:
[GroupA]
host1A ansible_host="1.2.3.4"

[GroupB]
host1B ansible_host="1.2.3.4"

What I would like to do is to have something like this

[GroupA]
host1A ansible_host=Host1

[GroupB]
host1B ansible_host=Host1

Is this feasible?
If it is not feasible, I will have to add all the variables in the inventory 
and this will not be so clean.

Best Regards,
Konstantinos

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3f453be4-1f87-48f3-bd80-95d679787761%40googlegroups.com.