ansible-2.x

Running Python script via ansible

◇◆丶佛笑我妖孽 提交于 2019-12-18 14:11:03
问题 I'm trying to run a python script from an ansible script. I would think this would be an easy thing to do, but I can't figure it out. I've got a project structure like this: playbook-folder roles stagecode files mypythonscript.py tasks main.yml release.yml I'm trying to run mypythonscript.py within a task in main.yml (which is a role used in release.yml). Here's the task: - name: run my script! command: ./roles/stagecode/files/mypythonscript.py args: chdir: /dir/to/be/run/in delegate_to: 127

Ansible remote_user vs ansible_user

孤人 提交于 2019-12-17 18:26:39
问题 The question is simple: what is the difference between ansible_user (former ansible_ssh_user ) and remote_user in Ansible, besides that the first one is set if configuration file and the latter one is set in plays / roles? How do they relate to -u / --user command line options? 回答1: They both seem to be the same. Take a look here: https://github.com/ansible/ansible/blob/c600ab81ee/lib/ansible/playbook/play_context.py#L46-L55 # the magic variable mapping dictionary below is used to translate #

Ansible - Could not use lookup file module for a file under /etc/

丶灬走出姿态 提交于 2019-12-17 15:00:50
问题 I am deploying a CentOS machine and one among the tasks was to read a file that is rendered the Consul service which places it under /etc/sysconfig . I am trying to later read it in a variable using the lookup module but it is throwing an error below: fatal: [ansible_vm1]: FAILED! => {"failed": true, "msg": "could not locate file in lookup: /etc/sysconfig/idb_EndPoint"} But I am running the lookup task way below the point where the idb_EndPoint file is generated and also I looked it up

ansible- expect module with cisco ios switch

被刻印的时光 ゝ 提交于 2019-12-13 06:32:13
问题 If I try to use expect module in YAML file like this: name: some tests hosts: sw-test gather_facts: False tasks: - name: do reload in case of "catting off" expect: command: reload in 30 responses: 'Reload scheduled in 30 minutes by admin on vty0 (192.168.253.20)\nProceed with reload? \[confirm\]' : y echo: yes But there is a problem with connection: root@Kali:/etc/ansible# ansible-playbook test3 -u admin -k -vvvv Using /etc/ansible/ansible.cfg as config file SSH password: Loaded callback

In Ansible how do you change a existing dictionary/hash values using a variable for the key

╄→尐↘猪︶ㄣ 提交于 2019-12-12 21:30:35
问题 As the title suggest i want to loop over an existing dictionary and change some values, based on the answer to this question i came up with the code below but it doesn't work as the values are unchanged in the second debug call, I'm thinking it is because in the other question they are creating a new dictionary from scratch, but I've also tried it without the outer curly bracket which i would have thought would have caused it to change the existing value. - set_fact: uber_dict: a_dict: some

Ansible : iterate over inventory groups

你说的曾经没有我的故事 提交于 2019-12-12 19:17:05
问题 I have group tgt-cluster includes 3 hosts. I have written down role to deploy container which is executing on tgt-cluster group. I am controlling the number of containers to deploy with with_sequence . My tasks looks like this. - name: Deploy Container docker_container: name: "C{{ item }}" image: "{{ image_name }}:{{ image_tag }}" recreate: yes detach: yes tty: yes interactive: yes with_sequence: count="{{ number_of_container_to_deploy }}" If I want to deploy one container, currently playbook

Running the Following Playbook syntax appears to be correct but getting following ERROR!- 'blockinfile' is not a valid attribute for a Play

Deadly 提交于 2019-12-12 14:46:08
问题 Running the Following Playbook syntax appears to be correct but getting following ERROR!- ERROR! 'blockinfile' is not a valid attribute for a Play The error appears to have been in '/root/playbook1.yml': line 2, column 3, but may be elsewhere in the file depending on the exact syntax problem. The offending line appears to be: --- - name: insertupdate ^ here My Playbook file code is: --- - name: insertupdate blockinfile: dest: /etc/network/interfaces block: | iface eth2 inet static address 192

ERROR! conflicting action statements (expect, command) in Ansible

吃可爱长大的小学妹 提交于 2019-12-12 13:33:39
问题 I'm trying to install java on several hosts with Ansible. I looked for some examples of expect module to provide answers to the prompts. I think this syntax is quite fine: - hosts: datanode sudo: yes sudo_user: root tasks: - expect: name: install java jdk 7 command: apt-get install openjdk-7-jdk responses: Question: 'Do you want to continue? [Y/n]': 'Y' But when I try to execute ansible-playbook file.yml I receive the error: ERROR! conflicting action statements (expect, command) The error

How to add spaces at beginning of block in Ansible's blockinfile?

百般思念 提交于 2019-12-12 07:44:41
问题 I found this blockinfile issue, where a user suggested adding a number after the "|" in the "block: |" line, but gives a syntax error. Basically, I want to use blockinfile module to add a block of lines in a file, but I want the block to be indented 6 spaces in the file. Here's the task - name: Added a block of lines in the file blockinfile: dest: /path/some_file.yml insertafter: 'authc:' block: | line0 line1 line2 line3 line4 I expect authc: line0 line1 line2 line3 line4 but get authc: line0

Ansible 2.0 upgrade - default filter chain error

纵饮孤独 提交于 2019-12-12 03:36:56
问题 Prior to Ansible 2.0, default filters were allowed "{{ oracle1.instance.reports|d().forecast|d().email|d('testing@gmail.com') }}" where |d() would allow a variable (such as reports or forecast ) to be defaulted to the default variable at the end (in this case, the default variable is testing@gmail.com ) if the program couldn't find an instance for reports or forecast . reports & forecasts are defined in some environments, but not in all, so I cannot remove these variables from the script line